Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Incorrect syntax near '-'.Must declare the scalar variable "@UserName

Reply
Thread Tools

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

 
 
roamnet@yahoo.com
Guest
Posts: n/a
 
      05-11-2007
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>
<asparameter Name="UserName" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="Password" Type="String" />
<asparameter Name="column1" Type="String" />
<asparameter Name="UserName" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="UserName" Type="String" />
<asparameter Name="Password" Type="String" />
<asparameter 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Line 1: Incorrect syntax near ')'. how to fix it levis ASP .Net 0 09-20-2006 10:19 AM
Incorrect syntax near 'int' David ASP .Net 7 04-07-2006 05:35 PM
Visual Studio Incorrect Syntax Near The Keyword Default Information JMUApache ASP .Net 2 09-04-2005 12:41 PM
SqlClient.SqlException: Line 1: Incorrect syntax near '='. Patrick Olurotimi Ige ASP .Net 4 03-18-2005 01:53 PM
System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near =?Utf-8?B?UGF0cmljay5PLklnZQ==?= ASP .Net 3 10-11-2004 10:21 AM



Advertisments