hi i'm new to the c# language and im having some trouble figuring what to do,
i wanted to put my database connections inside classes and have methods but im having trouble starting it, i have this code
this works just fine
but i wanted to put them my database connections and the save method inside a class, any suggestions and help on how to do it, thank you guys!
[EDIT: e-mail address removed]
i wanted to put my database connections inside classes and have methods but im having trouble starting it, i have this code
Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace PayrollManagement { public partial class EmployeeRegistration : Form { public EmployeeRegistration() { InitializeComponent(); } System.Data.SqlClient.SqlConnection con; System.Data.SqlClient.SqlDataAdapter da; DataSet ds1; int maxRows = 0; int inc = 0; private void EmployeeRegistration_Load(object sender, EventArgs e) { con = new System.Data.SqlClient.SqlConnection(); ds1 = new DataSet(); con.ConnectionString = "Data Source=SANQUI-PC;Initial Catalog=PayrollProject;Integrated Security=True"; string sql = "Select * From Emp_Acc_Info"; da = new System.Data.SqlClient.SqlDataAdapter(sql, con); con.Open(); da.Fill(ds1, "Emp_Acc_Info"); maxRows = ds1.Tables["Emp_Acc_Info"].Rows.Count; } public void btnSave_Click(object sender, EventArgs e) { /* System.Data.SqlClient.SqlCommandBuilder cb; cb = new System.Data.SqlClient.SqlCommandBuilder(da); DataRow dRow = ds1.Tables["Emp_Acc_Info"].NewRow(); dRow[0] = textBox1.Text; dRow[1] = textBoxFName.Text; dRow[2] = textBoxMName.Text; dRow[3] = textBoxLName.Text; dRow[4] = textBoxAddress.Text; if (radioButtonFemale.Checked) { dRow[5] = "Female"; } else if (radioButtonMale.Checked) { dRow[5] = "Male"; } dRow[6] = textBoxContact.Text; dRow[7] = textBoxEmail.Text; dRow[8] = textBoxDesc.Text; ds1.Tables[""].Rows.Add(dRow); maxRows = maxRows + 1; inc = maxRows - 1; da.Update(ds1, "Emp_Acc_Info"); con.Close(); MessageBox.Show("Entry Added");*/
but i wanted to put them my database connections and the save method inside a class, any suggestions and help on how to do it, thank you guys!
[EDIT: e-mail address removed]
Comment