views:

77

answers:

2

Hi Anyone,

Im going crazy with this. I did the ff:

  1. Create a datatable.
  2. Fill it from a SQL db thru SqlDataAdapter.
  3. Edit the datatable thru datagridview.
  4. Call the sqldataadapter.update but the changes are not persisted to the db.

A closer look at the datatable after editing, the row states were not updated even if i actually edited the datatable thru the datagridview but the edited DataRow(s) have changes in the item array. Really confusing.. Any ideas? Thanks.

A: 

Do you use DataBinding? Calling EndEdit may help...!

Baldi
DataBinding did not help. It's really confusing.
Jojo
+1  A: 

You need several things to make this work. If you drag the table from the Data Sources view you end up with a few different things on your GUI:

  1. a dataSet
  2. a bindingSource
  3. the TableAdapter
  4. a tableAdapterManager
  5. a BindingNavigator

With these in place you can look at the source code to see what hapens beind the scenes. You'll need the EndEdit (as Baldi said before) but you need a little more:

private void UpdateGridView()
{
    // validate that data types corresponds to database table column
    this.Validate();

    // ends edit on the graph table
    this.graphBindingSource.EndEdit();

    // ends edit on the graph table
    this.intervalBindingSource.EndEdit();

    // connect to the database - and exceute changes
    this.tableAdapterManager.UpdateAll(this.diagramDBDataSet);
}

Hopefully this gets you started. If you want to learn more - you can follow this .NET database slide show with the complementary database tutorial. Good luck!

BennySkogberg