C # DataTable.DefaultView.Sort Sorting method Use of the Merge property in a DataTable merge DataTable

Source: Internet
Author: User

Sort DataTable.DefaultView.Sort = "ID ASC" "

DataTable Merge 1 (must be the same structure DataTable) in the DataTable in the Merge property

Two DataTable merges, originally tested using the datatable Merge method to merge reads directly, one is to receive a lot of data types on both sides do not, one is to feel this is too simple. So when the program general report type is wrong, I abandoned this method instead of reading the values from the two DataTable to make a separate judgment display.

DataTable olddatatable=new DataTable ();

DataTable newdatatable=new DataTable ();

if (olddatatable!=null&&olddatatable.rows.count>0&&newdatatable!=null&& NEWDATATABLE.ROWS.COUNT>0)

{

Olddatatable.merge (newdatatable);

}

else if (olddatatable!=null&&olddatatable.rows.count>0&&newdatatable==null| | newdatatable.rows.count<=0)

{

Newdatatable.merge (olddatatable);

}

else if (..)

{

........

}

DataTable Merge 2

Using the Rows.Add method or the Datatable.importrow method

          DataTable newdatatable = Datatable1.clone ();                       Add DataTable1 data for            (int i = 0; i < DataTable1.Rows.Count; i++)            {                  DataRow row =datatable1.rows[i];                   NEWDATATABLE.ROWS.ADD (row);              }             Add DataTable2 data for              (int i = 0; i < DataTable2.Rows.Count; i++)              {                 datatable2.rows[i]. Itemarray.copyto (obj, 0);                NEWDATATABLE.ROWS.ADD (obj);                }

  

  Copy the structure and data of the DataTable1            DataTable newdatatable = Datatable1.copy ();            Add DataTable2 Data            foreach (DataRow dr in Datatable2.rows)            {                newdatatable.importrow (DR);            }

  

C # DataTable.DefaultView.Sort Sorting method Use of the Merge property in a DataTable merge DataTable

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.