Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取异常:此处给定的DataRow不在当前DataRowCollection中_C#_Ado.net - Fatal编程技术网

C# 获取异常:此处给定的DataRow不在当前DataRowCollection中

C# 获取异常:此处给定的DataRow不在当前DataRowCollection中,c#,ado.net,C#,Ado.net,我面临着一个问题 DataTable Dt1 = table1; DataTable Dt2 = Dt1.Copy(); DataRow[] row = Dt1.Select("Name = 'Test'"); foreach (DataRow row in Dt2) { Dt2.Rows.Remove(row); // Here The given DataRow is not in the current DataRowCollection } 它给出了一个例外,因为我从不同的行

我面临着一个问题

DataTable Dt1 = table1;
DataTable Dt2 =  Dt1.Copy();
DataRow[] row =  Dt1.Select("Name = 'Test'");

foreach (DataRow row in Dt2)
{
  Dt2.Rows.Remove(row); // Here The given DataRow is not in the current DataRowCollection
}
它给出了一个例外,因为我从不同的行中过滤日期,并将其从不同的行中删除


谢谢,Shivam

您当前的代码将删除Dt2数据表中的所有行,因为当您循环使用foreach语句时,您将覆盖Dt1中选定的行。

这将提供一个编译器错误,因为行被重新定义。。。您的实际代码是什么?什么是DataRow[]row=Dt1.Select(“Name='Test');?