我想從後面的Sql創建Linq查詢,但無法讓它工作。從SQL創建LINQ
SQL
"select distinct(roomName) as RoomName, tblroomid as RoomId
from TblMaster,tblrooms
where tblrooms.tblroomid = TblPresentationMaster.tblroomid
and convert(datetime, PDay, 101)='" + Pday + "'";
LINQ
(from tblRoom in tblRooms.AsEnumerable()
join tblPMaster in tblMaster.AsEnumerable()
on tblRoom.Field<int>("tblroomid") equals tblPMaster.Field<int>("tblroomid")
where tblPMaster.Field<string>("pday") == Pday
select tblRoom.Field<string>("roomName")).Distinct();
如果我嘗試運行它
foreach (var myReader in query)
{
}
我收到以下錯誤
指定的轉換無效。
這些都是在下面的變量值,希望這有助於在捕獲錯誤
tblPMaster.pday = Jun 28 2011 12:00AM
Parameter Pday = 28/11/2011
我不知道我做錯了。有人可以幫助獲得正確的LINQ查詢嗎?
你有什麼具體的代碼問題? – Servy
@Servy對不起,我錯過了錯誤的詳細信息,現在我已經添加了它。 – javadotnetcoder
例外是告訴你,你的類型之一是錯誤的。 – Jason