Israel

Israel

  • 700
  • 1.3k
  • 217.6k

Refreshing my database

Jul 16 2014 9:10 AM
Hi!
 
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):
Have a look please:
 
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();
}
}
}
 

Answers (4)