我在數據表中對數據進行分組,並總結了使用LINQ一列,但同時運行時,我收到錯誤,指出得到錯誤無法施展DBNull.Value鍵入「System.Int32
無法施展DBNull.Value鍵入'System.Int32。請使用可空類型」下面是我的代碼
Dim resultStyle = invData.Tables(0).AsEnumerable() _
.GroupBy(Function(v) New With {Key .InvestorStyleID = v.Field(Of Integer)("InstitutionalInvestorStyleID"), Key .StyleName = Not IsNothing(v.Field(Of String)("InstitutionalInvestorStyleName"))}) _
.Select(Function(v) New With {Key .InvestorStyleID = v.Key.InvestorStyleID, Key .StyleName = v.Key.StyleName, Key .Sum = v.Sum(Function(r) Double.Parse(r.Item("k001ICGeo").ToString()))})
請建議我如何避免走空value.I我在第二行收到錯誤
.GroupBy(Function(v) New With {Key .InvestorStyleID = v.Field(Of Integer)("InstitutionalInvestorStyleID"), Key .StyleName = Not IsNothing(v.Field(Of String)("InstitutionalInvestorStyleName"))}).
我不想取空值
我相信問題是InstitutionalInvestorStyleID。檢查數據庫中是否可以空。試試'v.Field(Of Integer?)(「InstitutionalInvestorStyleID」)' – shadow