简体   繁体   中英

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. it return a horrible error that i failed to troubleshoot. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'nvarchar'.

Must declare the scalar variable "@P_C_ID".

Source Error:

An unhandled exception was generated during the execution of the current web request. 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'. 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 runBehavior, 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 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 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">

it's because the syntax of the query being executed internally in sql server is wrong. it generally occurs due to your wrong inputs. please provide the code section that raises the problem for an efficient solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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