When inserting the ROW in a table in another table, "the row is already a table" error

xiaoxiao2021-03-14  210

When you write the code last time, when you insert the ROW in a table, use the code, there is an error in "the row is another table":

DIM TABLE2 AS New DataTable Table2 = Table1.clone

FOR Each Row As DataRow in Table1.Rows Table2.NewRow () Table2.Rows.Add (Row) Next

2 tables of the same structure, cannot use this method Copy a row to another table.

But we can use the way:

DIM TABLE2 AS New DataTable Table2 = Table1.clone

For Each Row As DataRow in Table1.Rows Table2.Importrow (ROW) Next

There is a note on the MSDN:

When you call newrow, you will add a row to the table when you populate the table and populate the default value, and set DataRowState to Added. Calling ImportRow will retain existing DataRowState and other values ​​in the row.

转载请注明原文地址:https://www.9cbs.com/read-129317.html

New Post(0)