DataRow复制一行到另一个DataTable
下面两个方法是DataRow复制一行到另一个DataTable的,直接Add会出错“此行已属于另一个表”,其实以前就知道怎么做的,可每次要用到的时候还是犯糊涂,这次把它们记下来。
1.用DataRow.ItemArray
DataTable t=new DataTable();
DataRow r=t.NewRow();
r.ItemArray=oldRow.ItemArray;
t.Rows.Add(r);
2.用DataTable.ImportRow()
t.ImportRow(oldRow);
1.用DataRow.ItemArray
DataTable t=new DataTable();
DataRow r=t.NewRow();
r.ItemArray=oldRow.ItemArray;
t.Rows.Add(r);
2.用DataTable.ImportRow()
t.ImportRow(oldRow);
本文介绍了两种将DataRow从一个DataTable复制到另一个DataTable的方法:使用ItemArray属性和ImportRow方法。避免了直接添加时出现的“此行已属于另一个表”的错误。
2947

被折叠的 条评论
为什么被折叠?



