這是我的代碼指定的轉換是無效的例外
var result = (from row1 in table.AsEnumerable()
join row2 in tabelPopup.AsEnumerable()
on row1.Field<string>("CallID") equals
row2.Field<string>("callID")
where row1.Field<string>("Direction") == "I"
select new
{
Agent = row1.Field<string>("Agent"),
StartTime = row1.Field<DateTime>("StartTime"),
Reason = row2.Field<string>("Reason")
});
其中table
和tablePopup
是數據表變量。
我得到這個異常:
Specified cast is not valid
這個代碼:
new
{
Agent = row1.Field<string>("Agent"),
StartTime = row1.Field<DateTime>("StartTime"),
Reason = row2.Field<string>("Reason")
}
您確定列定義正確嗎?即Agent是字符串,StartTime是日期時間,Reason是字符串? – artm 2014-10-07 10:43:48
顯然,其中一個字段包含一個類型的值,這不是'Field'方法所期望的(假設它只是'(T)row [fieldName]')。 –
Dennis
2014-10-07 10:45:55
@artm你是對的,'datetime'應該是'string',請輸入一個答案以接受它 – 2014-10-07 10:46:43