Vb.net 连接linq中的两个数据表时出错

Vb.net 连接linq中的两个数据表时出错,vb.net,linq,join,Vb.net,Linq,Join,我有以下代码 Dim hardlimit As DataTable = From f In dealDataTable.AsEnumerable Join f2 In hardlimithit.AsEnumerable On f.Field(Of Integer)("dea_ID") Equals f2.Field(Of Integer)("ID")

我有以下代码

Dim hardlimit As DataTable = From f In dealDataTable.AsEnumerable
                                    Join f2 In hardlimithit.AsEnumerable
                                    On f.Field(Of Integer)("dea_ID") Equals f2.Field(Of Integer)("ID")
                                    Select f
我试图选择从“dealDataTable”获取所有数据,其中id与我的另一个datatable的id字段匹配

我从这个代码中得到这个错误

System.InvalidCastException was caught
  HResult=-2147467262
  Message=Unable to cast object of type '<JoinIterator>d__61`4[System.Data.DataRow,System.Data.DataRow,System.Int32,System.Data.DataRow]' to type 'System.Data.DataTable'.
  Source=FMSOvernight
  StackTrace:
       at FMSOvernight.Module1.RunLimitCalculations() in C:\Cloud Source Control\Funding Management Overnighter\FundingManagementSystemOvernightRoutine\Module1.vb:line 273
       at FMSOvernight.Module1.StartGeneration() in C:\Cloud Source Control\Funding Management Overnighter\FundingManagementSystemOvernightRoutine\Module1.vb:line 135
  InnerException: 
捕获到System.InvalidCastException HResult=-2147467262 消息=无法将类型为“d_u61`4[System.Data.DataRow,System.Data.DataRow,System.Int32,System.Data.DataRow]”的对象强制转换为类型为“System.Data.DataTable”。 来源=FMS 堆栈跟踪: 在C:\Cloud Source Control\Funding Management Overnighter\FundingManagementSystemOvernightRoutine\Module1.vb中的fmsNighter.Module1.RunLimitCalculations()处:第273行 在C:\Cloud Source Control\Funding Management Overnighter\FundingManagements SystemOvernightRoutine\Module1.StartGeneration()中的fmsNighter.Module1.StartGeneration()处:第135行 内部异常:
您选择的行是这样的
IEnumerable
,它不是
数据表。您可以使用:

但请注意,如果没有行,此方法将抛出一个
invalidoOperationException
。你必须先检查一下。例如:

Dim hardlimitTable As DataTable = dealDataTable.Clone() ' empty table with the same columns '
If hardlimitRows.Any() Then
    hardlimitTable = hardlimitRows.CopyToDataTable()
End If
Dim hardlimitTable As DataTable = dealDataTable.Clone() ' empty table with the same columns '
If hardlimitRows.Any() Then
    hardlimitTable = hardlimitRows.CopyToDataTable()
End If