表T1( 「P 01」)和T2( 「DTM」)包含以下值如何加入空值兩個表中引用的字段
Table t1
PO101(string) Loop_Id (Int)
Item_1 6
Item_2 8
---
Table t2
DTM02(string) Loop_Id(int)
20141029 (null)
20141029 6
20141101 8
這個查詢
var records = (from t1 in x12.InterchangeDataSet.Tables["PO1"].AsEnumerable()
join t2 in x12.InterchangeDataSet.Tables["DTM"].AsEnumerable()
on t1.Field<string>("Loop_Id") equals t2.Field<string>("Loop_Id")
select new{A = t1.Field<string>("PO101"),B=t2.Field<string>("DTM02")});
失敗與
base {System.SystemException} =
{"Cannot cast DBNull.Value to type 'System.Int32'. Please use a nullable type."}
因爲t2.Loop_id中的空值。
如果我在t2中刪除包含空值的行,它工作正常。
如何將Loop_Id強制轉換爲可空或避免加入表中任何一個爲null的行?
木孔德,沒有同樣的事情.. – TonyP 2014-10-31 13:55:24