asp.net DataTable Merge

Source: Internet
Author: User
Tags add object count net

Two structure-like DataTable merging

 
 
  1. DataTable DataTable1 = new DataTable ();
  2. DataTable DataTable2 = new DataTable ();
  3. DataTable newdatatable = Datatable1.clone ();
  4. object[] obj = new Object[newdatatable.columns.count];
  5. for (int i = 0; i < DataTable1.Rows.Count; i++)
  6. {
  7. Datatable1.rows[i]. Itemarray.copyto (obj,0);
  8. NEWDATATABLE.ROWS.ADD (obj);
  9. }
  10. for (int i = 0; i < DataTable2.Rows.Count; i++)
  11. {
  12. Datatable2.rows[i]. Itemarray.copyto (obj,0);
  13. NEWDATATABLE.ROWS.ADD (obj);
  14. }
  15. Or
  16. DataTable DataTable1 = new DataTable ();
  17. DataTable DataTable2 = new DataTable ();
  18. object[] obj = new Object[datatable1. Columns.count];
  19. for (int i = 0; i < DataTable2.Rows.Count; i++)
  20. {
  21. Datatable2.rows[i]. Itemarray.copyto (obj,0);
  22. DATATABLE1.ROWS.ADD (obj);
  23. }
  24. DataTable DataTable1 = new DataTable ();
  25. DataTable DataTable2 = new DataTable ();
  26. DataTable newdatatable = Datatable1.clone ();
  27. object[] obj = new Object[newdatatable.columns.count];
  28. for (int i = 0; i < DataTable1.Rows.Count; i++)
  29. {
  30. Datatable1.rows[i]. Itemarray.copyto (obj,0);
  31. NEWDATATABLE.ROWS.ADD (obj);
  32. }
  33. for (int i = 0; i < DataTable2.Rows.Count; i++)
  34. {
  35. Datatable2.rows[i]. Itemarray.copyto (obj,0);
  36. NEWDATATABLE.ROWS.ADD (obj);
  37. }
  38. Or
  39. DataTable DataTable1 = new DataTable ();
  40. DataTable DataTable2 = new DataTable ();
  41. object[] obj = new Object[datatable1. Columns.count];
  42. for (int i = 0; i < DataTable2.Rows.Count; i++)
  43. {
  44. Datatable2.rows[i]. Itemarray.copyto (obj,0);
  45. DATATABLE1.ROWS.ADD (obj);
  46. }



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.