Using the dataSet.Merge method

S

Steve

Hiya

I am passing a dataset to a middle-tier object, which in turn updates the
data source and retrieves an Identity value from the database, replacing the
ID value in my dataset with the correct value. When the function returns to
the UI layer, the dataset that I passed to the middle function has the
updated ID, whereas the dataset on the UI layer still has the original
value.

I tried the merge the 2 datasets together in order to update the UI data
with the refreshed data from the DB. If I used the
uiDataSet.Merge(middleDataSet) method, then the changes are not applied to
the UI dataset. If I used the uiDataSet.Merge(middleDataSet, True) then the
changes are applied to the UI dataset, but I have an extra row in my
dataset!

I assume this is because I am altering the PK value in the middle dataset
after the insert into the database. I've read the help on this topic and it
suggests using the merge, but it doesn't change the PK value, just an Item
value.

The code I'm using is below:

Dim oSecurity As New myMiddleTierObject
'// Persist the updates to the data source
If m_oDataSet.HasChanges = True Then
Dim oTemp As DataSet = m_oDataSet.GetChanges
Try
If Not oTemp Is Nothing Then
If oSecurity.Update(oTemp, m_oUserPrincipal) = True Then
'// oTemp contains the correct ID value, need to update the
UI
m_oDataSet.Merge(oTemp, True)
m_oDataSet.AcceptChanges()
End If
End If
Catch Ex As Exception
m_oDataSet.RejectChanges()
Throw Ex
End Try
End If

I guess that by changing the PK value, the merge method struggles to update
the existing record and adds a new one. Does anyone know how to deal with
this issue?

Kind Regards,
Steve.
 
S

Steve

Hi Brad

Thanks for the link, I haven't seen that.

This poses a big problem for me. I do the Merge in the UI layer, which has
no idea what a DataAdapter is. Even my Business Layer doesn't know what data
adapter I'm using cos that's all defined in my Data Access layer, which
simply exposes certain methods that are provider independant.

I guess I'll have to make another trip to the server :blush:(

Cheers,
Steve.
 

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