我想从后面的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