hi wang chi,
I want to update the datagridview, and not the database. I already saved data from user input textboxes directly into the db. All I want is to update/refresh the datagridview with latest row from the db. This is how I add user input data to the db:
SqlConnection con = new SqlConnection("myConnectionString");
string myQuery = "Insert into tblUser values ('" + TextBox1.Text + "'," + "'" + TextBox2.Text + "')";
SqlCommand cmd = new SqlCommand(myQuery, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (System.Exception err)
{
//Catch exception here
}
finally
{
dgvUserUpdate(); con.Close();
}
private void dgvUserUpdate(){ this.tblUserBindingSource.EndEdit();
dgvUser.DataSource = dmsDataSet1.tblUser;
dgvUser.Refresh();
}
Here as you can see, method named dgvUserUpdate() is specially created to update/refresh the datagridview but I can't make it loaded with latest info. I guess there is something wrong with my codes for that method.