How to merge multiple able and add datatable to Dataset

Source: Internet
Author: User

MergeThe method is to combine two similar datatables into a datatable:

// Create table 1 datatable dt1 = new datatable (); // Add dt1.columns data. 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 table 2 datatable dt2 = new datatable (); // Add dt2.columns data. 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 (), "**"});} // create table 3 datatable dt3 = NULL; // copy the structure in table 1 to table 3dt3 = dt1.clone (); // MERGE table 1 and table 2 to Table 3if (dt3! = NULL) {dt3.merge (dt1); dt3.merge (dt2); this. datagridview1.datasource = dt3 ;}

 

Add datatable to Dataset

// Create ableabledatatable 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 (), "**"});} // Add the able to datasetdataset DS = new dataset (); DS. tables. add (DT); this. datagridview1.datasource = Ds. tables [0]. defaultview;

 

 

 

 

 

 

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.