http://blog.csdn.net/huyu107/article/details/53509171
Overview
Take a row from one DataTable and put it in another DataTable. Error: the row already belongs to another table .
The first method:
DataTable dt = new DataTable();dt = ds.Tables["All"].Clone();//克隆All的结构传递给dtDataRow[] dr=this.dataSet31.Tables["Product"].Select("bc=1"); //通过条件得到符合条件的行for(int i=0;i<dr.Length;i++){ //将数组元素加入表... dt.Rows.Add(dr[i]);//出错提示为:该行已经属于另一个表}// 修改后DataTable dt = new DataTable();dt = ds.Tables["All"].Clone();//克隆All的结构传递给dtDataRow[] dr=this.dataSet31.Tables["Product"].Select("bc=1"); //通过条件得到符合条件的行for(int i=0;i<dr.Length;i++){ //将数组元素加入表... dt.Rows.Add(dr[i].ItemArray);}
The second method:
DataTable DT1=New DataTable ();D atatable CALCDT=New DataTable ();//dt1 just get the table structure, no data; //calcdt has a table structure, with data //original method foreach (DataRow Dr in calcdt. Rows) {Dt1. Rows//Improved Method DataRow Drcalc;foreach (DataRow Dr in Calcdtrows) {Drcalc = dt1= dr. Rows
C # places a DataTable row into another DataTable