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!