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

Discussion in 'ASP .Net' started by roamnet@yahoo.com, May 11, 2007.

  1. Guest

    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(SqlException exception,
    Boolean breakConnection) +177
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
    exception, Boolean breakConnection) +68

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

    System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(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.InternalExecuteNonQuery(DbAsyncResult
    result, String methodName, Boolean sendToPipe) +413
    System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +115

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

    System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(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(GridViewRow row,
    Int32 rowIndex, Boolean causesValidation) +1216
    System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
    causesValidation, String validationGroup) +853
    System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source,
    EventArgs e) +87
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    args) +35
    System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
    EventArgs e) +117
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
    args) +35
    System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
    +86
    System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
    eventArgument) +154

    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)
    +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, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiggaz
    Replies:
    6
    Views:
    32,220
    Raghudubba
    Nov 5, 2009
  2. =?Utf-8?B?S2VuIEFkZW5pamk=?=

    Must declare the scalar variable '@FirstName'

    =?Utf-8?B?S2VuIEFkZW5pamk=?=, Apr 26, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    80,359
    leojose
    Aug 17, 2007
  3. Oded Dror

    Must Declare the Scalar Variable error

    Oded Dror, May 28, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    19,053
    Oded Dror
    May 28, 2006
  4. Mark
    Replies:
    1
    Views:
    1,545
  5. Ken Adeniji

    Must declare the scalar variable '@FirstName'

    Ken Adeniji, Apr 26, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    131
    Ken Adeniji
    Apr 26, 2005
Loading...

Share This Page