Copy DataTable to DataTable keeping the PrimaryKey
I need to copy
dt2
intodt1
but I can't usedt1 = dt2
becausedt1
has a primary key whiled开发者_如何学Pythont2
does not. What's the best way to do this?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.
精彩评论