我正在尝试在VB.NET WPF解决方案中通过区域桥接两个数据表和组的LINQ查询。LINQ查询抛出抛出异常
我接收关于这些行“无效转换异常”:
.MfstCt = ZoneGroup.Count(Function(c) c.Field(Of String)("ConsignmentNumber")), _
.ArticleCt = ZoneGroup.Count(Function(c) c.Field(Of String)("ArticleNumber")) _
的错误状态:
从字符串“B4B0158234”转换到类型“布尔”无效。
但我在查询中看不到任何转换为布尔值。
字段ConsignmentNumber
位于最前面的表格中,字段ArticleNumber
位于文章表格中。我在下面添加了整个查询。任何人都可以帮助建议我去哪里错了吗?
Dim query = _
From Mfst In tblMFst.AsEnumerable() _
Join article In tblArticle.AsEnumerable() _
On Mfst.Field(Of Integer)("PCMSConsignment_ID") Equals _
article.Field(Of Integer)("PCMSConsignment_ID") _
Group Mfst By Zone = Mfst.Field(Of String)("PostZone") Into ZoneGroup = Group
Select New With _
{ _
Key Zone, _
.MfstCt = ZoneGroup.Count(Function(c) c.Field(Of String)("ConsignmentNumber")), _
.ArticleCt = ZoneGroup.Count(Function(c) c.Field(Of String)("ArticleNumber")) _
}
For Each x In query
Console.WriteLine(x.Zone, x.MfstCt, x.MfstCt)
Next
编辑:我已经改变了代码,以反映正确的(Of String)
和更新正在接收的错误消息。
异常应该告诉你想要的实际类型是 - 异常说的是什么? –
这意味着至少有一行'ConsignmentNumber'或'ArticleNumber'列有非'int'或空值。 – MarcinJuraszek
完整的例外是“System.Data.DataSetExtentions.dll中发生类型为'System.InvalidCastException'的未处理异常 其他信息:指定的转换无效。” – Zabman