Retrieve only changed values from a DataRow ?

  • Thread starter Thread starter Rune B
  • Start date Start date
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();
}
 
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
 
Back
Top