DetailsView Update Error

Machaira

Junior Contributor
Joined
Aug 19, 2002
Messages
325
Location
Abingdon, MD
OK, I'm stumped on this. I've got an ASP.NET 2.0 page with a DetailsView on it, tied to a SQLDataSource.

Here's the SQL Server 2000 data table I'm using:

[dbo].[CDRL Infromation] (
[cdrlID] [int] IDENTITY (1, 1) NOT NULL ,
[OPFI #] [varchar] (255)
[DID #] [varchar] (50)
[Field Instruction Title] [varchar] (255)
[Gov Lead] [varchar] (255)
[Due] [varchar] (100)
[Next Due Date] [datetime]
[Current Rev Date] [datetime]
[Current Rev] [float]
[SME] [varchar] (255)
[TECH WRITER] [varchar] (255)
[Days to Next Update] [int]

Here's the SELECT and UPDATES for the data source:

SELECT * FROM [CDRL Infromation] WHERE ([cdrlID] = @cdrlID2)

UPDATE [CDRL Infromation] SET [OPFI #] = @column1, [DID #] = @column2, [Field Instruction Title] = @Field_Instruction_Title, [Gov Lead] = @Gov_Lead, [Due] = @Due, [Next Due Date] = @Next_Due_Date, [Current Rev Date] = @Current_Rev_Date, [Current Rev] = @Current_Rev, [SME] = @SME, [TECH WRITER] = @TECH_WRITER, [Days to Next Update] = @Days_to_Next_Update WHERE [cdrlID] = @original_cdrlID


I attempt to edit a record and when I click the Update link on the detailsview I get:


Line 1: Incorrect syntax near 'nvarchar'.
Line 1: Incorrect syntax near ','.
Line 1: Incorrect syntax near ')'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'nvarchar'.
Line 1: Incorrect syntax near ','.
Line 1: Incorrect syntax near ')'.

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): Line 1: Incorrect syntax near 'nvarchar'.
Line 1: Incorrect syntax near ','.
Line 1: Incorrect syntax near ')'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857354
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734966
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +149
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +415
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +401
System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +721
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +78
System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation) +1152
System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +461
System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +109
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +163
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102





Where the heck is the nvarchar coming from?!? I've tried looking at the data in the ItemUpdating event but it doesn't really present anything useful.

Any suggestions would be helpful.
 
"nvarchar" is probably the SQL data type that the SqlDataSource is using for your parameter variables. I have found that the SqlDataSource seems to like the parameter names to be the same as the field name (plus the "@" prefix). So, if I have a field named "my_field", SqlDataSource likes the parameter to be named "@my_field". I used to name my parameters something like "@MyField", but ran into some problems, especially with stored procedures.

How did you fill in the values for your parameters? Remember that the Name property for a Parameter object must not have the "@" prefix.

E.g.
Visual Basic:
[size=2]TestRunDataSource.SelectParameters.Add([/size][size=2][color=#800000]"system_id"[/color][/size][size=2], txtSystemId.Text)[/size]
[size=2]
[/size]

Not
Visual Basic:
[/size]
 
TestRunDataSource.SelectParameters.Add([size=2][color=#800000]"@system_id"[/color][/size][size=2], "System1")[/size]
[size=2]

I really think it has something to do with your parameters.

Todd
 
Back
Top