数据库兼容模式设置

chen553152469 2010-11-09 10:17:12
我的sql语句是select * from Course where datediff(day,updatetime,getdate())>=30 and Type = @Type CourseTime like '%白天班%' ,在数据库可以查询出来,在vs中却报错。
"day" 不是可识别的表提示选项。如果它要作为表值函数的参数,请确保您的数据库兼容模式设置为 90。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.SqlClient.SqlException: "day" 不是可识别的表提示选项。如果它要作为表值函数的参数,请确保您的数据库兼容模式设置为 90。

源错误:


行 227: catch (Exception ex)
行 228: {
行 229: throw ex;
行 230: }
行 231: finally


源文件: C:\Documents and Settings\Administrator\桌面\xiangmu\LSWeb\LSWebDAL\DBHelper.cs 行: 229

堆栈跟踪:


[SqlException (0x80131904): "day" 不是可识别的表提示选项。如果它要作为表值函数的参数,请确保您的数据库兼容模式设置为 90。]
LSWebDAL.DBHelper.GetDataTable(String sql, SqlParameter[] values) in C:\Documents and Settings\Administrator\桌面\xiangmu\LSWeb\LSWebDAL\DBHelper.cs:229
LSWebDAL.CourseService.GetAllCourseByTime(Int32 Period, Int32 Start, Int32 Price, Int32 typeid, String Name) in C:\Documents and Settings\Administrator\桌面\xiangmu\LSWeb\LSWebDAL\CourseService.cs:1228
LSWebBLL.CourseManager.GetAllCourseByTime(Int32 Period, Int32 Start, Int32 Price, Int32 typeid, String Name) in C:\Documents and Settings\Administrator\桌面\xiangmu\LSWeb\LSWebBLL\CourseManager.cs:215

[TargetInvocationException: 调用的目标发生了异常。]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +71
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +261
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +488
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1247
System.Web.UI.WebControls.BaseDataList.GetData() +38
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +153
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +54
System.Web.UI.WebControls.BaseDataList.DataBind() +55
System.Web.UI.WebControls.BaseDataList.EnsureDataBound() +60
System.Web.UI.WebControls.BaseDataList.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +44
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842




...全文
619 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
obuntu 2010-11-09
  • 打赏
  • 举报
回复
select * from Course where datediff(day,updatetime,getdate())>=30 and Type = @Type CourseTime like '%白天班%'

少了个and吧

select * from Course where datediff(day,updatetime,getdate())>=30 and Type = @Type and CourseTime like '%白天班%'
heymal 2010-11-09
  • 打赏
  • 举报
回复
设置兼容模式:

USE [master]
GO
ALTER DATABASE [DBname] SET COMPATIBILITY_LEVEL = 90
GO

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧