我正在尝试从表中读取数据到数据gridview中。需要从网格视图的网页中编辑此数据。 它返回一个可怕的错误,我未能解决。 异常详细信息:System.Data.SqlClient.SqlException:'nvarchar'附近的语法不正确。
必须声明标量变量“ @P_C_ID”。
源错误:
在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息。
堆栈跟踪:
[SqlException(0x80131904):'nvarchar'附近的语法不正确。
必须声明标量变量“ @P_C_ID”。]
System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔值breakConnection,操作1 wrapCloseInAction) +2555722
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)+5958412
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔调用方HasConnectionLock,布尔asyncClose)+285
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,Boolean&dataReady)+4169
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,字符串resetOptionsString,布尔值isInternal,布尔值forDescribeParameterEncryption,布尔值shouldCacheForAlwaysEncrypted)+255
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,布尔异步,Int32超时,任务和任务,布尔asyncWrite,布尔inRetry,SqlDataReader ds,布尔describeParameterEncryptionRequest)+2598
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔值returnStream,字符串方法,TaskCompletionSource 1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +1483
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource
1完成,字符串方法名,布尔值sendToPipe,Int32超时,布尔值和usedCache,布尔值asyncWrite,布尔值inRetry) 374
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()+286
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand命令,DataSourceOperation操作)+392
System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary键,IDictionary值,IDictionary oldValues)+670
System.Web.UI.DataSourceView.Update(IDictionary键,IDictionary值,IDictionary oldValues,DataSourceViewOperationCallback回调)+106
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow行,Int32 rowIndex,布尔原因验证)+1210
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e,布尔causeValidation,字符串验证组)+877
System.Web.UI.WebControls.GridView.OnBubbleEvent(对象源,EventArgs e)+89
System.Web.UI.Control.RaiseBubbleEvent(对象源,EventArgs args)+37
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(对象源,EventArgs e)+90
System.Web.UI.Control.RaiseBubbleEvent(对象源,EventArgs args)+37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)+121
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)+161
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)+12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)+15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)+9884018
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+1639
当我单击“编辑”按钮并且要执行的查询为 UpdateCommand =“ UPDATE [Performance_Rating_2] SET [策略目标] = @STRATEGIC_OBJECTIVE,[发起并采取措施] = @INITIATIVE_AND_ACTION,[措施] = @采取措施, [TARGET] = @TARGET,[体重第一半] = @WEIGHT_FIRST_HALF,[体重第二半] = @WEIGHT_SECOND_HALF,[评分第一半] = @RATING_FIRST_HALF, [SCORE FIRST HALF] = @SCORE_FIRST_HALF,[RATING SECOND HALF] = @RATING_SECOND_HALF,[SCORE SECOND HALF] = @SCORE_SECOND_HALF,[证据第一半] = @EVIDENCE_FIRST_HALF,[证据第二半] = @EVIDENCE_SECOND_HALF,[负责人] = @RESPONSIBLE_PERSON,[P_C_ID] = @P_C_ID“>
答案 0 :(得分:-1)
这是因为在sql server内部执行的查询语法错误。通常是由于您输入错误而引起的。 请提供引起问题的代码部分,以寻求有效的解决方案。