This is how to insert the the value in the table. Here I'm inserting the values in the registration table on the button event.
private void Register_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=.\\sqlexpress; initial catalog=yourDatabasename; integrated security=true");
try
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into Registration values('" + textBox1.Text + "','" + textBox2.Text + "','" + comboBox1.Text + "','" + textBox4.Text + "')", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Congratulation! Successfully Register!");
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error Got:" + ex.Message);
}
}
Here how you can update the record
private void Chpawrd_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=.\\sqlexpress; initial catalog=yourDatabasename; integrated security=true");
try
{
con.Open();
SqlCommand cmd = new SqlCommand("update registration set password='" + textBox3.Text + "' where username='" + textBox1.Text + "'", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Password changed Successfully");
}
catch (Exception ex)
{
MessageBox.Show("Error:-" + ex.Message);
}
con.Close();
Here I'm updating the existed password. Where the username is from the
texbox1
and the related password from this username will be changed.
And the
delete
option you can use as same the
update
with the
where
condition. I think this will help you.