I have fetched some data from a SQL database into a datagridview, but after the user modified the data in the datagridview, how can I upload the data back?
And also, I found a code like this:
this.dataGridView1.Update();
What does this method Update? Here is the code where I bind the data to datagridview:
SqlDataReader read;
SqlCommand cmd;
DataTable dt = new DataTable();
cmd = new SqlCommand("Select * from Table", 204.192.49.3);
read = cmd.ExecuteReader();
dt.Load(read);
dataGridView1.DataSource = dt;
The easiest way is to create a temporary DataSet, fill it with data using a SqlDataAdapter and then passing it as dataGridView’s DataSource. This code should do the trick:
DataSet temp = new DataSet();SqlDataAdapter SDA = new SqlDataAdapter();
SqlCommand command = new SqlCommand();
SqlConnection connection = new SqlConnection();
string connstring = "YourConnectionString";
And then in the method you want to trigger the update do this:
This should solve your problem.