Merge two data tables with the same structure under asp. ent

Source: Internet
Author: User

Wrote a function.
Copy codeThe Code is as follows:
/// <Summary>
/// Merge two identical datatables and return the Merged Results
/// </Summary>
/// <Param name = "dt1"> </param>
/// <Param name = "dt2"> </param>
/// <Returns> </returns>
Public DataTable CombineTheSameDatatable (DataTable dt1, DataTable dt2)
{
If (dt1.Rows. Count = 0 & dt2.Rows. Count = 0)
{
Return new DataTable ();
}
If (dt1.Rows. Count = 0)
{
Return dt2;
}
If (dt2.Rows. Count = 0)
{
Return dt1;
}
DataSet ds = new DataSet ();
Ds. Tables. Add (dt1.Copy ());
Ds. Merge (dt2.Copy ());
Return ds. Tables [0];
}

Due to the limited understanding of C #, I don't know why I cannot correctly judge the empty table with dt1 = null, so I used the method of several rows.

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.