我建设我的ASP.NET MVC项目动态查询由以下:执行SELECT语句日期在WHERE子句失败
Dim queryString As String = "SELECT VALUE userInfos FROM MyDBEntities.UserInformations AS userInfos"
If strWhere <> "" Then
queryString = queryString & " WHERE " & strWhere
End If
' Call the constructor with the specified query and the ObjectContext.
Dim SearchUsersQuery As New System.Data.Objects.ObjectQuery(Of UserInformation)(queryString, MyDB)
Dim lstOfUsers As List(Of UserInformation) = SearchUsersQuery.ToList
凡基本strWhere是我建立一个动态的字符串根据用户选择搜索的内容进行过滤。
这很好,直到我需要添加日期比较日期条款。
我想以下几点:
strWhere = " userInfos.BirthDate <= " & StartDateForQuery.ToShortDateString
这将最终成为:
"SELECT VALUE userInfos FROM MyDBEntities.UserInformations AS userInfos Where userInfos.BirthDate <= 10/09/1992"
但是当我尝试用ToList执行查询时的日期是在哪里串我收到以下错误:
The argument types 'Edm.DateTime' and 'Edm.Int32' are incompatible for this operation. Near WHERE predicate, line 1, column 103.
关于我的问题的任何想法?
在此先感谢
有两个问题:数据库供应商是什么?数据库中的BirthDate的格式是什么? – 2010-09-10 03:59:38
这是一个Microsoft SQL Server数据库。 BirthDate是DateTime类型的 – Matt 2010-09-10 05:48:52
你是如何执行这个查询的? – 2010-09-10 06:15:23