回答1

You need to create a new Row with the values from dr first. A DataRow can only belong to a single DataTable.

 

You can also use Add which takes an array of values:

myTable.Rows.Add(dr.ItemArray)

Or probably even better:

// This works because the row was added to the original table.
myTable.ImportRow(dr);

// The following won't work. No data will be added or exception thrown.
var drFail = dt.NewRow()
drFail["CustomerID"] = "[Your data here]";
// dt.Rows.Add(row); // Uncomment for import to succeed.
myTable.ImportRow(drFail);

 

回答2,重点是用ImportRow这个方法

Try this:

DataTable dt = (DataTable)Session["dtAllOrders"];
DataTable dtSpecificOrders = dt.Clone();

DataRow[] orderRows = dt.Select("CustomerID = 2");

foreach (DataRow dr in orderRows)
{
    dtSpecificOrders.ImportRow(dr);
}

 

回答3

yourTable.ImportRow(dataRow);

It's because the row you're copying doesn't have the same TableName:

For example, try:

Table1.TableName = "Table1";
Table2.TableName = "Table2";

 

相关文章:

  • 2021-12-29
  • 2021-07-18
  • 2021-12-31
  • 2021-08-05
  • 2022-12-23
  • 2021-12-11
  • 2022-02-24
  • 2021-12-31
猜你喜欢
  • 2021-12-19
  • 2021-12-16
  • 2021-12-04
  • 2022-12-23
  • 2021-06-08
  • 2021-06-26
  • 2018-04-17
相关资源
相似解决方案