Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to Make a Copy of a DataRow's Values

$
0
0

I'd like to be able to capture a copy of a strongly type DataRow's values so that I can see if the user changed them when I look at them in the Validated event handlers for the input controls to which the DataRow fields are bound in some cases and not bound in others. 

I've read that I can Import the row into a new DataTable, thereby making a copy of it.  But that means I need to clone the DataTable, which I'd like to avoid since there's no direct utility to me. 

I've also looked at comparing the strongly typed DataRow value to the row's Original Version as noted in the code below, but that looks cumbersome and I've learned that I need to invoke DataRow.EndEdit() after each set of changes in order to have the Original row updated with the new values.  That's fine with fields that are data bound (I do the EndEdit anyway), but some fields are not bound for reasons I won't go into.

So, is there any way to make a standalone copy of an original strongly typed DataRow that I can simply compare to a possibly changed copy as shown in the desired approach below?

Thanks.  Steve

// Clunky compare against Original row that requires EndEdit()
if (drLive.Field1 != drLive[dsLive.dtLive.Field1Column.ColumnName, DataRowVersion.Original]) ...

// Desired approach
drCopy = drLive.Copy()
if (drCopy.Field1 != drLive.Field1) ...


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>