DataSet.Merge - Expressions not recalculated - Known Bug?



When merging a DataSet, if the the DataSet being merged into contains an
expression column and the DataSet merging does not, then the expression
column is not evaluated for new rows (they are DBNull). Of course, I strip
the expression column before updating because of the other bug that causes
DataAdapter Update to blow up if an Expression column is present, so this
causes the aforementioned bug to occur.

Is this a known bug? The workaround is to reset the column.Expression
property after a merge.


William Ryan eMVP

Cole, what does your merge statement look like? What is preserveChanges set
to and do you have MissingSchemaAction set to add for instance?


Ryan, I have done the Merge with preserveChanges true and false with
MissingSchemaAction.Add and Ignore and had the same results.

William Ryan eMVP

My apologies there, I got confused for second. I had this problem a long
time ago and the two work arounds I found were resetting the expression
afterward as you mentioned or trap the rowchnaged event and force the
expression there. I couldn't find any sort of refresh but I guess it's the
caused by when expressions evaluate. Resetting the property seems like a
fair compromise though but this will work too: As far as the blowing up
issue, I think your problem may be refreshing the dataset after you update.
If you are using the DataAdapter Wizard, this is on by default. Then it
requries the DB, and tries to write to this field and blows up. Setting
ContinueUpdateOnError should fix it but that leads to many other potential
problems. So, in the Wizard, when you are on the query builder screen,
choose Advanced Options and turn off the Refresh dataset option...or you can
just change the params in the Select statemant that's appended to the update
so that value in the expressino doesn't get changed.



Dim dcExp As New DataColumn("MyColumn", Type.GetType("System.String"))

dcExp.Expression = "LastName + ', ' + FirstName"


dg.DataSource = ds

AddHandler ds.Tables(0).RowChanged, AddressOf myFunction

ds.Merge(ds2, True, MissingSchemaAction.AddWithKey)

End Sub

Public Sub myFunction(ByVal Sender As Object, ByVal e As

e.Row.Item(3) = CType(e.Row.Item(2), String) + ", " + CType(e.Row.Item(1),

End Sub

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