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();
}
}
}
IsraelPosted Jul 16, 2014, 2:04 PM
conn = new SqlConnection(connstr);
VulpesPosted Jul 16, 2014, 11:19 AM
IsraelPosted Jul 16, 2014, 10:54 AM
I fill it like this in load event
string connectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=master;Integrated Security=True";
VulpesPosted Jul 16, 2014, 10:06 AM
If so, then how did you fill it in the first place - by binding to a datatable (or other data source) or manually?