Go The DataTable add row appears "This row already belongs to another table" Error!

Source: Internet
Author: User


1DataTable DT1 =NewDataTable ();2 3DataTable DT2 =NewDataTable ();4 5 //Create a structure for DT16 7DataColumn PName =NewDataColumn ("name");8Pname.datatype = System.Type.GetType ("System.String");9DataColumn Pcount =NewDataColumn ("Quantity");TenPcount.datatype = System.Type.GetType ("System.Int32"); One DT1. Columns.Add (pName); A - DT1. Columns.Add (pcount); - //Add test Data the - for(inti =0; I <Ten; i++) - { -DataRow dr =DT1. NewRow (); +Dr[pname] ="Name"; -Dr[pcount] =i; + DT1. Rows.Add (DR); A } atGridcontrol.datasource =dt1; - - //cloning the structure of the DT1 to DT2 -DT2 =DT1. Clone (); - for(inti =0; I <2; i++) - { inDataRow dr =DT2. NewRow (); -Dr =DT1. Rows[i]; to //This line indicates that the row already belongs to another table + //DT2. Rows.Add (DR); - //This is correct, or you can use DT2 directly. Rows.Add (DT1. Rows[i]. ItemArray); the DT2. Rows.Add (Dr. ItemArray); * } $Gridcontrol.datasource =DT2;Panax NotoginsengGridcontrol.refreshdatasource ();

Go The DataTable add row appears "This row already belongs to another table" Error!

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.