Retrieve only changed values from a DataRow ?

R

Rune B

- I need to find the columnNames of values that has Changed in a certain
DataRow, and I can't quite figure out how to do it right ... The following
does seems a little clumsy, and does not work right either.

Anybody knows how to do it?


private IList<string> GetChangedFieldsColumnNames(DataRow row)
{
List<string> result = new List<string>();
if(row != null)
{
switch(row.RowState)
{
case DataRowState.Detached:
break;
case DataRowState.Modified:
case DataRowState.Added:
foreach(DataColumn column in row.Table.Columns)
{
try
{
object originalValue = row[column, DataRowVersion.Original];
object newValue = row[column, DataRowVersion.Current];
if(originalValue != newValue)
{
result.Add(column.ColumnName);
}
}
catch(VersionNotFoundException)
{
}
}
break;
case DataRowState.Deleted:
case DataRowState.Unchanged:
break;
}
}
return result.ToArray();
}
 
G

Guest

Hi,

you could retrive in a daatset object only records which have change with
the GetChanges function of a dataset object.
Then creat a datview object by filtering only rowstate

hope it help
serge
 

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