Reading Data From SQL Server Using Gridview asp.net

-2

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, Action1 wrapCloseInAction) +2555722 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 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, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +1483 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 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, IDictionary 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) +15 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">

c#
asp.net
gridview
asked on Stack Overflow Aug 29, 2018 by V. Shikongo • edited Aug 29, 2018 by V. Shikongo

1 Answer

-1

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.

answered on Stack Overflow Aug 29, 2018 by uma mahesh

User contributions licensed under CC BY-SA 3.0