Today, we encountered a situation where we read the information of several customers meeting condition 1 from a data table, read the information of several customers meeting condition 2, and finally display the information. because the structure of the customer information of the first and second data is identical, it is better to merge the data into a able and assign the value to the gridview. wrote a function.
/// <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.