简体   繁体   English

使用 Gridview asp.net 从 SQL Server 读取数据

[英]Reading Data From SQL Server Using Gridview asp.net

I am trying to read data from the the table into a data gridview.我正在尝试将表中的数据读取到数据网格视图中。 This data required to be edited from the webpage in a gridview.这些数据需要从 gridview 中的网页进行编辑。 it return a horrible error that i failed to troubleshoot.它返回一个我未能解决的可怕错误。 Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'nvarchar'.异常详细信息:System.Data.SqlClient.SqlException:'nvarchar' 附近的语法不正确。

Must declare the scalar variable "@P_C_ID".必须声明标量变量“@P_C_ID”。

Source Error:源错误:

An unhandled exception was generated during the execution of the current web request.执行当前 Web 请求期间生成了未处理的异常。 Information regarding the origin and location of the exception can be identified using the exception stack trace below.可以使用下面的异常堆栈跟踪来识别有关异常来源和位置的信息。

Stack Trace:堆栈跟踪:

[SqlException (0x80131904): Incorrect syntax near 'nvarchar'. [SqlException (0x80131904): 'nvarchar' 附近的语法不正确。 Must declare the scalar variable "@P_C_ID".] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction) +2555722 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction) +5958412 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean 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, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) +255 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavi必须声明标量变量“@P_C_ID”。] System.Data.SqlClient.SqlConnection.OnError(SqlException 异常, Boolean breakConnection, Action 1 wrapCloseInAction) +2555722 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction) +5958412 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +285 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, TdsParserdCoReader , Boolean& dataReady) +4169 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) +255 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehaviorcmd)运行行为or, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2598 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource 1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +1483 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource 1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +374 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +286 System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +392 System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +670 System.Web.UI.DataSourceView.Update(IDictionary keys, IDi或者,Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2598 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource 1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +1483 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource 1 完成、String methodName、Boolean sendToPipe、Int32 超时、Boolean&usedCache、Boolean async、Write Boolean 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 keys, IDi ctionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +106 System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1210 System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +877 System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +89 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +90 System.Web.UI.Control.RaiseBubbleEvent(Object source, 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) +1操作值,IDictionary oldValues,DataSourceViewOperationCallback 回调) +106 System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causeValidation) +1210 System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean原因验证,字符串验证组)+877 System.Web.UI.WebControls.GridView.OnBubbleEvent(对象源,EventArgs e)+89 System.Web.UI.Control.RaiseBubbleEvent(对象源,EventArgs args)+37 System.Web.UI .WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +90 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.LinkBut​​ton.OnCommand(CommandEventArgs e) +121 System.Web.UI.WebControls.LinkBut​​ton.RaisePostBackEvent(String eventArgument) +161 System.Web.UI.WebControls.LinkBut​​ton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12 System.Web.UI.Page。 RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +1 5 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9884018 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639 5 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9884018 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639

The error is fired when i click the edit button and the query to be executed is UpdateCommand="UPDATE [Performance_Rating_2] SET [STRATEGIC OBJECTIVE] = @STRATEGIC_OBJECTIVE, [INITIATIVE AND ACTION] = @INITIATIVE_AND_ACTION, [MEASURE] = @MEASURE, [TARGET] = @TARGET, [WEIGHT FIRST HALF] = @WEIGHT_FIRST_HALF, [WEIGHT SECOND HALF] = @WEIGHT_SECOND_HALF, [RATING FIRST 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_FIRST_HALF, [EVIDENCE SECOND HALF] = @EVIDENCE_SECOND_HALF, [RESPONSIBLE PERSON] = @RESPONSIBLE_PERSON WHERE [P_C_ID] = @P_C_ID">当我单击编辑按钮并且要执行的查询是 UpdateCommand="UPDATE [Performance_Rating_2] SET [STRATEGIC OBJECTIVE] = @STRATEGIC_OBJECTIVE, [INITIATIVE AND ACTION] = @INITIATIVE_AND_ACTION, [MEASURE] = @MEASURE, [目标] = @TARGET,[重量前半部分] = @WEIGHT_FIRST_HALF,[重量第二部分] = @WEIGHT_SECOND_HALF,[评分前半部分] = @RATING_FIRST_HALF,[得分前半部分] = @SCORE_FIRST_HALF COND , [SCORE SECOND HALF] = @SCORE_SECOND_HALF, [EVIDENCE FIRST_HALF] = @EVIDENCE_FIRST_HALF, [EVIDENCE SECOND HALF] = @EVIDENCE_SECOND_HALF, [RESPONSIBLE_PERSON] = @RESPONSIBLE_PERSON WHERE] = @P_C_ID

it's because the syntax of the query being executed internally in sql server is wrong.这是因为在 sql server 内部执行的查询的语法是错误的。 it generally occurs due to your wrong inputs.它通常是由于您的错误输入而发生的。 please provide the code section that raises the problem for an efficient solution.请提供提出问题的代码部分以获得有效的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM