Why won't merged dataset update database?

  • Thread starter Thread starter Mike Hnatt
  • Start date Start date
M

Mike Hnatt

I'm baffled. My data store (database) is not updating with a refreshed
dataset.

Here's what is going on:

1) Create a dataset from a table in a database.
2) Create a copy of this dataset and maniuplate (update some records)
3) Now, merge this copied dataset back into the original dataset (using the
Merge method)
4) Now display this original dataset in a datagrid to prove the data has
been updated
5) Now update the database with this modified dataset <<<<DOESN'T HAPPEN

Reason I'm using a copied dataset (for paging stuff to maintain viewstate).

Everything works, and I have bound the modified dataset to a datagrid to
show that indeed the values were updated.
Here is my code: Help! Mike
Dim objDB As New dbconnection
Dim strConn As String = objDB.GetDBConnectionStringWeb
Dim cn As New System.Data.OleDb.OleDbConnection(strConn)
Dim da As New OleDbDataAdapter("SELECT * FROM Summary", cn)
Dim ds As New DataSet
cn.Open()
da.Fill(ds, "Summary")
ds.Merge(myUpdatedDataSet.Summary, False, MissingSchemaAction.Add)
ds.AcceptChanges()
Dim cb As New OleDb.OleDbCommandBuilder(da)
da.UpdateCommand = cb.GetUpdateCommand()
da.Update(ds, "Summary")
DataGrid2.AllowPaging = False
DataGrid2.DataSource = ds
DataGrid2.DataBind()
cn.Close()
 
I found out why. Just remove the line "ds.AcceptChanges()". It now works.
Don't ask me why, but it does update the database now.
Mike
 
Back
Top