Link to home
Start Free TrialLog in
Avatar of bradmq
bradmq

asked on

VB.NET Dataset doesn't seem to update actual data source

I have the following code:

objAdapter.Fill(objDataSet)
...
objDataSet.Tables("Table").Rows(Row).BeginEdit()
objDataSet.Tables("Table").Rows(Row).Item("TimeAccumulator") = objDataSet.Tables("Table").Rows(Row).Item("TimeAccumulator") + PingRate
objDataSet.Tables("Table").Rows(Row).EndEdit()
...
objDataSet.AcceptChanges
Dim oCB As OleDbCommandBuilder = New OleDbCommandBuilder(objAdapter)
objAdapter.Update(dsModified)

which runs without any errors, but the data source (i have tried both MS Access 2002 and SQL 2000) does not get updated.

I know that the dataset has my changes in it because I have called the objDataSet.GetXML method and written the XML to the event log and I can see my changes.

What am I missing?

Avatar of MattWare
MattWare

Where does dsModified come from?  You seem to have updated the objDataSet object - not dsModified.  objDataSet.GetXML shows your changes, but do you see them in dsModified.GetXML since that is what you are passing to the update call?

--M
Avatar of bradmq

ASKER

Whoops,

I posted code between edits.  The line should actually read

objAdapter.Update(objDataSet)

I had had some code previously that looked like this:

Dim dsModified As New DataSet()
dsModified = objDataSet.GetChanges

then I was calling

objAdapter.Update(dsModified)

This didn't work either so I had simplified it to just passing the dataset to the Update method.

Brad

Those are supposed to be parens and not brackets...
Ignore that post please...wrong window.
Avatar of bradmq

ASKER

I figured out the problem:

The Update method on the adapter has to be called before the Acceptchanges method on the dataset!

Seems stupid and counter intuitive but I guess if I needed to rollback, I could call dataset.rejectchanges and call the adapter.update method again.
ASKER CERTIFIED SOLUTION
Avatar of PashaMod
PashaMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial