By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,191 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,191 IT Pros & Developers. It's quick & easy.

Incorrect syntax near '-'.Must declare the scalar variable "@UserName

P: n/a
hi
i created database file with .mdf extention ,sql server as a source
and use grid view to display data
there're no problem in data retrieve and display,but i want to edit it
or insert new records
there is an error "Incorrect syntax near '-'.
Must declare the scalar variable "@UserName".
I worked out in design view,code is automatically generated.Iam not
able fix the error.
Iam working with Visual Web Developer-2005 Express Edition

The error page diplayed is

Server Error in '/myweb' Application.
Incorrect syntax near '-'.
Must declare the scalar variable "@UserName".
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: Incorrect
syntax near '-'.
Must declare the scalar variable "@UserName".

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 '-'.
Must declare the scalar variable "@UserName".]
System.Data.SqlClient.SqlConnection.OnError(SqlExc eption exception,
Boolean breakConnection) +177
System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException
exception, Boolean breakConnection) +68

System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject
stateObj) +199
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj) +2305
System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader
ds, RunBehavior runBehavior, String resetOptionsString) +147

System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
async) +1021
System.Data.SqlClient.SqlCommand.RunExecuteReader( CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, DbAsyncResult result) +314

System.Data.SqlClient.SqlCommand.InternalExecuteNo nQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe) +413
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +115

System.Web.UI.WebControls.SqlDataSourceView.Execut eDbCommand(DbCommand
command, DataSourceOperation operation) +392

System.Web.UI.WebControls.SqlDataSourceView.Execut eUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +643
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary
values, IDictionary oldValues, DataSourceViewOperationCallback
callback) +78
System.Web.UI.WebControls.GridView.HandleUpdate(Gr idViewRow row,
Int32 rowIndex, Boolean causesValidation) +1216
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +853
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,
EventArgs e) +87
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +35
System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)
+86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +154

System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+4919
Version Information: Microsoft .NET Framework Version:2.0.50727.42;
ASP.NET Version:2.0.50727.210

Program Code:

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Modify.aspx.vb" Inherits="lesson6_Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
DeleteCommand="DELETE FROM [Munni1] WHERE [UserName] =
@UserName" InsertCommand="INSERT INTO [Munni1] ([UserName],
[Password], [E-Mail]) VALUES (@UserName, @Password, @column1)"
SelectCommand="SELECT * FROM [Munni1]"
UpdateCommand="UPDATE [Munni1] SET [Password] = @Password, [E-Mail] =
@column1 WHERE [UserName] = @UserName">
<DeleteParameters>
<asp:Parameter Name="UserName" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="column1" Type="String" />
<asp:Parameter Name="UserName" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="UserName" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="column1" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<br />
&nbsp;</div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="UserName"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" />
<asp:BoundField DataField="UserName"
HeaderText="UserName" ReadOnly="True" SortExpression="UserName" />
<asp:BoundField DataField="Password"
HeaderText="Password" SortExpression="Password" />
<asp:BoundField DataField="E-Mail" HeaderText="E-Mail"
SortExpression="E-Mail" />
</Columns>
</asp:GridView>
</form>
</body>
</html>

Thanks
Kranthi

May 11 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.