I want to refresh my database after saving my records. I cant do that... But I wrote this line of code in red (without success):
conn = new SqlConnection(connstr);
comm = new SqlCommand();
conn.Open();
SqlParameter firstname = new SqlParameter("@firstname", SqlDbType.VarChar);
SqlParameter lastname = new SqlParameter("@lastname", SqlDbType.VarChar);
comm.Parameters.Add(firstname);
comm.Parameters.Add(lastname);
firstname.Value = txtfirstname.Text;
lastname.Value = txtlastname.Text;
comm.Connection = conn;
comm.CommandText = "insert into test values(@firstname,@lastname)";
try
{
comm.ExecuteNonQuery();
dgv.CurrentCell = dgv.Rows[dgv.Rows.Count - 1].Cells[0]; //Here
MessageBox.Show("Saved!");
}
catch (Exception)
{
MessageBox.Show("Not saved");
}
finally
{
conn.Close();
}
}
}