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