在预期条件的上下文中指定的非布尔类型的表达式,接近' AdmissionID'

时间:2015-08-01 06:51:07

标签: c# sql asp.net database-connection jointable

' /'中的服务器错误应用

  

在预期条件的上下文中指定的非布尔类型的表达式,接近' AdmissionID'。

说明:

在执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

例外详细信息:

  

System.Data.SqlClient.SqlException:在预期条件的上下文中指定的非布尔类型的表达式,接近' AdmissionID'。

来源错误:

  

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。

堆栈追踪:

[SqlException (0x80131904): An expression of non-boolean type specified in a context where a condition is expected, near 'AdmissionID'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1767866
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5352418
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1691
   System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +61
   System.Data.SqlClient.SqlDataReader.get_MetaData() +90
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +365
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1406
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +134
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +140
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +316
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +86
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1481
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +101
   System.Web.UI.WebControls.ListControl.PerformSelect() +34
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
   System.Web.UI.WebControls.BaseDataBoundControl.set_RequiresDataBinding(Boolean value) +9844021
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewChanged(Object sender, EventArgs e) +15
   System.Web.UI.DataSourceView.OnDataSourceViewChanged(EventArgs e) +105
   System.Web.UI.WebControls.SqlDataSourceView.SelectParametersChangedEventHandler(Object o, EventArgs e) +31
   System.Web.UI.WebControls.ParameterCollection.OnParametersChanged(EventArgs e) +20
   System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +142
   System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +101
   System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +36
   System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +257
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +589
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +101
   System.Web.UI.WebControls.ListControl.PerformSelect() +34
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
   System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +23
   System.Web.UI.Control.PreRenderRecursiveInternal() +83
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974

我的SQL命令是这样的&gt;&gt; SELECT * FROM [Bed] WHERE WardID = @WardID AND BedStatus = 'Available' AND BedNo NOT IN (SELECT BedNo FROM [AdmissionDetail], [Admission] WHERE ([AdmissionDate] <= @AdmissionDate AND [DischargeDate] >= @DischargeDate AND AdmissionStatus <> 'Discharged' AND [AdmissionDetail]AdmissionID = [Admission]AdmissionID))

我使用Visual Studio 2013并使用asp:DropDownList和asp:SqlDataSource来执行此操作。 我有4张表,即入场费,入场费,病房和床位。

1 个答案:

答案 0 :(得分:1)

table alias条款中column namewhere之间缺少

..[AdmissionDetail].AdmissionID = [Admission].AdmissionID

还要记下几点。

始终使用正确的INNER JOIN加入两个表而不是旧样式的commma分隔连接,并在<{1}}子句中单独保留过滤器

代替where条款Not In可能会提升效果,Not exists会在NOT IN返回任何sub-query值时失败

NULL