背景:做需求时,需要将一个datatable中满足条件的datarow拷贝另一个结构相同的表中
原做法如下:
dt_childrenP.Rows.Add(dt_childrenAll.Rows[k]);
报错结果为“该行已经属于另一个表”
正确的写法:
dt_childrenP.Rows.Add(dt_childrenAll.Rows[k].ItemArray);
即:by datarow的ItemArray属性,通过数组来设置或获取此行的所有值,而不能直接通过拷贝行来设置或获取