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
 
Joined
Jul 24, 2007
Messages
1
Reaction score
0
pls add the following lines of code:
sourceAdapter.AcceptChangesDuringFill = false;
targetAdapter.AcceptChangesDuringFill = false;
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top