good day, hope everyone is well :)
I'm a first year student, and we just started with windows forms. I want to update data from DataGridview
into my database using a button but I have to create an update method in a data handler class
and call it in my form load, this is what I have tried so far.
DataHandler class:
public void UpdateStudent(int number, string name, string surname, string dob, string gender, int phone, string address)
{
try
{
//string updateQuery = @"UPDATE Student SET number='" + number + "'name='" + name + "'surname='" + surname + "'dob='" + dob + "'gender'" + gender + "'phone='" + phone + "'address='" + address + "'";
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.ExecuteNonQuery();
MessageBox.Show("updated successfully....");
}
catch (Exception ex)
{
MessageBox.Show("not updated!", ex.Message); m
}
finally
{
conn.Close();
}
}
update button on form load:
DataHandler dh = new DataHandler();
dh.UpdateStudent(int.Parse(txtStuID.Text), txtStuName.Text, txtStuSurname.Text,txtStuDOB.Text,txtStuGender.Text, int.Parse(txtStuNo.Text), txtStuAddress.Text);