Why won't merged dataset update database?

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()
 
M

Mike Hnatt

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top