2012-09-13 26 views
0

我用兩個表(A & B),以獲得不屬於那裏B.項目列表中選擇一個LINQ直接鑄造的錯誤

Dim results1 = From table1 In dt2 Where Not (From table2 In dt1 Where DirectCast(table2(0), String) = DirectCast(table1(0), String)).Any() Select DirectCast(table1(0), String) 

,但我得到的錯誤

Unable to cast object of type 'System.Double' to type 'System.String'. 

我需要做什麼轉換?

+1

爲什麼你需要做轉換呢?兩列的實際類型是什麼?你目前沒有給我們一個明確的問題。 –

回答

2

這裏不要使用'DirectCast' - 使用「table2(0).ToString()」或'CType'。

+0

工作。謝謝。 – Olivarsham

1

如果你喜歡LINQ,爲什麼不考慮實體框架。它將您的表格轉換爲強類型類,並將字段作爲類的屬性。使用LINQ時添加一些真正的簡單性。