Merging DataSets

  • Thread starter Thread starter Guido Kraus
  • Start date Start date
G

Guido Kraus

I have a strongly-typed DataSet that contains a
DataTable 'Customers' that is populated by a database.
The user can edit this table via DataGrid.

I want to supply a 'Refresh' button, that queries the
database and updates my DataTable to reflect the latest
changes other users may have made. Of course, I don't
want to lose the changes the current user has made and
which are not saved yet.

For this to work I use the Merge() method of the DataSet
in the following way:

Dim tempTable As New myDataSet.CustomersDataTable
myCustomersDataAdapter.Fill(tempTable)
MyDataSet.Merge(tempTable, True,
MissingSchemaAction.Ignore)

The problem is that after merging _all_ rows in my
target 'Customers' DataTable have a RowState
of 'Modified'. Even worse, the target 'Customers'
DataTable does not reflect the changes that were loaded
into the tempTable. In other words, immediately after
filling the tempTable contains all customers from the
database and all rows have RowState=Unchanged. After
merging with the target table, the target table does not
show the current changes. Instead all rows in the target
table have RowState=Modified.

BTW, I tested the merge operation with the second
parameter set to False. In this case, everything works as
excepted. However, this is no solution because the user's
changes would be overwritten by the version from the
tempTable.

Any ideas?
Thanks,
Guido
 
Hi Guido,

This behavior of DataSet.Merge() is actually by design. If the
preserveChanges is set to true, the RowState property will be set to
Modified when merging. However, I've checked your requirements and found
that the function cannot be achieved by simply call Merge(). Because if two
user have both modified the same row, there will be conflicts. You have to
manually select which one to keep. I think you can achieve this by writing
your own merging method.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top