Datatable's merge method and addition of datatable to Dataset

Source: Internet
Author: User
The merge method combines two data tables with similar structures into one data table:
Instance Code :
    //  Create Table1    Datatable dt1  =     New  Datatable (); dt1.columns. Add (  "  ID  " ); Dt1.columns. Add (  "  Name  "  ); Dt1.columns. Add (  "  PWD  "  );  For  (  Int  I  =     0  ; I  <    5  ; I  ++  ) {Dt1.rows. Add (  New     Object  [] {I. tostring (),  "  Name  "     +  I. tostring (),  "  **  " });}  //  Create Table2    Datatable dt2  =     New  Datatable (); dt2.columns. Add (  "  ID  "  ); Dt2.columns. Add (  "  Name  "  ); Dt2.columns. Add ( "  PWD  "  );  For  (  Int  I  =     5  ; I  <     10  ; I  ++  ) {Dt1.rows. Add ( New     Object  [] {I. tostring (),  "  Name  "     +  I. tostring (),  "  **  "  });}  //  Merge two tables   Datatable dt3  =     Null  ; Dt3  =  Dt1.clone ();  If  (Dt3  ! =     Null  ) {Dt3.merge (dt1); dt3.merge (dt2 );  This  . Datagridview1.datasource  =  Dt3 ;} 

Add datatable to Dataset

  Datatable dt  =     New  Datatable (); DT. Columns. Add (  "  ID  "  ); DT. Columns. Add (  "  Name  "  ); DT. Columns. Add (  " PWD  "  );  For  (  Int  I  =     0  ; I  <     10  ; I  ++  ) {DT. Rows. Add (  New    Object  [] {I. tostring (),  "  Name  "  +  I. tostring (),  "  **  "  });} Dataset DS  =     New  Dataset (); DS. Tables. Add (DT );  This . Datagridview1.datasource  =  DS. Tables [  0  ]. Defaultview; 
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.