C # DataRow comparison

Source: Internet
Author: User

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 ;}}}
    
   

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.