C # DataRow comparison
////// DataRow comparison ////////////Columns to be compared ///
Public static bool DataRowCompare (DataRow drA, DataRow drB, string [] columnNames) {bool flag = false; // sort ColumnSort (drA, columnNames) for comparison in DataRow ); columnSort (drB, columnNames); // resetting DBNull should be DBNull and ResetColumnCellValue (drA) cannot be serialized; ResetColumnCellValue (drB); // fill the list with only the List of columns to be comparedListA = GetNeedCompareData (drA, columnNames); ListListB = GetNeedCompareData (drB, columnNames); // compare string strA = EntityClassXmlSerializer
>. ToXMLString (listA); string strB = EntityClassXmlSerializer
>. ToXMLString (listB); if (strA = strB) {flag = true;} return flag ;}///
/// Obtain the data filling list set from the columns to be compared //////
///
///
Private static List
GetNeedCompareData (DataRow dr, string [] columnNames) {ListList = new List(); If (dr! = Null & columnNames! = Null) {foreach (string columnName in columnNames) {if (dr. table. columns. contains (columnName) {list. add (dr [columnName]);} else {// list. add (DBNull. value); list. add (null) ;}} return list ;}////// Sort by column name in the array /////////Sort public static void ColumnSort (DataRow drA, string [] columnNames) by column name in an array {// drA sort int I = 0; foreach (string columnName in columnNames) {if (drA. table. columns. contains (columnName) {drA. table. columns [columnName]. setOrdinal (I); I ++ ;}}}////// Reset DBNull in the cell to null //////Private static void ResetColumnCellValue (DataRow dr) {foreach (DataColumn dc in dr. table. columns) {if (dr [dc. columnName] is DBNull) {dr [dc. columnName] = null ;}}}