开发者

Copy DataTable to DataTable keeping the PrimaryKey

  1. I need to copy dt2 into dt1 but I can't use dt1 = dt2 because dt1 has a primary key while d开发者_如何学Pythont2 does not. What's the best way to do this?

  2. Is is possible to add a primary key to an existing dataTable which is not empty?

Thanks


I was just searching for how to set primary key - found solution:

dt2.PrimaryKey = new DataColumn[] { dt2.Columns["ColumnName"] };

I needed this for merging datatables, so it might help to copy one into an other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜