private void button1_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=DELL-PC\\SQLEXPRESS;Initial Catalog=NGOIdatabase;Integrated Security=True"); conn.Open(); try { SqlCommand comd = conn.CreateCommand(); comd.CommandType = CommandType.Text; if (textBox2.Text == "") { //MessageBox.Show("I will create new"); comd.CommandText = "INSERT INTO Employees (Name, father_name, Phone_num, Address, Designation, emp_salary) values ('" + textBox1.Text + "','" + textBox6.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox7.Text + "','" + textBox5.Text + "')"; } else { //MessageBox.Show("I will update"); comd.CommandText = "UPDATE Employees SET Name='" + textBox1.Text + "',father_name='" + textBox6.Text + "',Phone_num='" + textBox3.Text + "',Address='" + textBox4.Text + "',Designation='" + textBox7.Text + "',Emp_salary='" + textBox5.Text + "' where Emp_id=" + textBox2.Text; } comd.ExecuteNonQuery(); comd.CommandType = CommandType.Text; dataGridView1.DataSource = edb.selectall(); conn.Close(); } catch (Exception e2) { //MessageBox.Show(e2.Message); } reset_layout(); this.Close(); Employees a = new Employees(); a.Show(); }
private void Employees_Load(object sender, EventArgs e) { FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; TopMost = false; dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Arial", 10); dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; Employeesdb edb = new Employeesdb(); dataGridView1.DataSource = edb.selectall(); }