Reputation: 62554
Duplicate of: Update DataSet, How ? and Simple Update Dataset question by the same user.
I have this code that show result in DataGridView.
I want that any change in Cell of the Datagridview will change also the dataset
how i can do it ?
adp = new SqlDataAdapter("SELECT Fname,Lname,City,Sel from men order by Lname", Conn);
dsView = new DataSet();
adp.Fill(dsView, "men");
adp.Dispose();
dataGridView1.DataSource = dsView.Tables[0].DefaultView;
Upvotes: 0
Views: 1415
Reputation: 11995
First you've to set the appropriate insert, update & delete commands for you adapter. While creating the commands map the parameters properly with fields in the datatable. (ref SourceColumn parameter in SqlParameter constructor).
Next do you update, insert, or delete within your datagird and then call the adapter's Update() passing the dataset as parameter. The rest is magic.
PS: I'm not sure if a default view will work; try the datatable instead:
dataGridView1.DataSource = dsView.Tables[0];
Upvotes: 1