I got my form "InsertClient" and I have the button click method
public void Insert_Button_Click(object sender, EventArgs e)
{
MyClass.InsertNewClient(fullNametxt.Text, shortNametxt.Text);
fullNametxt.Clear();
shortNametxt.Clear();
fullNametxt.Focus();
GridView.Update();
GridView.Refresh();
}
My class recieve this:
public static void InsertNewClient (String fullName, String shortName)
{
SqlConnection conn = DBClass.ConnectionString.GetConnection();
SqlCommand cmd = new SqlCommand("MyStoredProcedure", conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@fullName", fullName);
cmd.Parameters.AddWithValue("@shortName", shortName);
int i = cmd.ExecuteNonQuery();
if (i == 0)
{
MessageBox.Show("Can't save data");
}
if (i > 0)
{
MessageBox.Show("Data saved!");
}
}
The thing is, the data is saved but that the DataGridView does not refresh after each INSERT (button click). I have to close the form and re-open it and appears refreshed.
Please help, I want the DataGridView refresh after INSERT data