Copy able (including table structure and data)

Source: Internet
Author: User

If you add the datatable returned by the program to a custom dataset, you can directly use the DS. Tables. Add (DT) method.
Datatable already belongs to another dataset "error. At this time, we need to create a new able and import the structure and data of the original datatable.
To the new able, you can use the following method (of course, the method is not the only ONE ):

 

/// <Summary> <br/> // copy the datatable <br/> /// </Summary> <br/> /// <Param name = "copydt"> data source </param> <br/> /// <Param name = "tablename"> after copying the new able name </param> <br/> /// <returns> </returns> <br/> private datatable copydatatable (datatable copydt, string tablename) <br/>{< br/> datatable dt = new datatable (tablename); <br/> foreach (datacolumn columm in copydt. columns) <br/>{< br/> DT. columns. add (columm. columnname, columm. datatype); <br/>}< br/> foreach (datarow row in copydt. rows) <br/>{< br/> DT. begininit (); <br/> DT. importrow (ROW); <br/> DT. endinit (); <br/>}< br/> return DT; <br/>}

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.