private void button5_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to delete user = "******"Delete Recoed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { dataGridView1.DataSource = null; dataGridView1.ClearSelection(); if (conn.State == ConnectionState.Closed) { conn.Open(); try { cmd.CommandText = "delete from userdata where uid=" + textBox1.Text; da.DeleteCommand = cmd; da.DeleteCommand.ExecuteNonQuery(); MessageBox.Show("Row deleted successfully", "Delete Record", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception Mye) { MessageBox.Show(Mye.ToString()); } ds.Tables.Clear(); ds.Clear(); conn.Close(); textBox1.Text = ""; textBox1.Enabled = false; textBox2.Text = ""; textBox3.Text = ""; } } }
private void button3_Click(object sender, EventArgs e) { dataGridView1.DataSource = null; dataGridView1.ClearSelection(); if (conn.State == ConnectionState.Closed) { conn.Open(); try { if (Otag == 0) { cmd.CommandText = "Insert into userdata(uname,cnic) values('" + textBox2.Text + "','" + textBox3.Text + "')"; da.InsertCommand = cmd; da.InsertCommand.ExecuteNonQuery(); MessageBox.Show("Row inserted successfully", "Insert Record", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { cmd.CommandText = "update userdata set uname= '" + textBox2.Text + "',cnic='" + textBox3.Text + "' where uid =" + textBox1.Text; da.UpdateCommand = cmd; da.UpdateCommand.ExecuteNonQuery(); MessageBox.Show("Row Updated successfully", "Update Record", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception Mye) { MessageBox.Show(Mye.ToString()); } ds.Tables.Clear(); ds.Clear(); conn.Close(); } button1.Enabled = true; button2.Enabled = true; button4.Enabled = true; button5.Enabled = true; button3.Enabled = false; button6.Enabled = false; textBox1.Text = ""; textBox1.Enabled = false; textBox2.Text = ""; textBox3.Text = ""; }