Error: Too many arguments specified

  • Error:Too Many Arguments Specified

    Posted: 03-03-2005 05:03 AM

    Hi,

    I'm pretty new to ASP.NET so I'm having some problems

    I'm trying to insert a users registration info into the DB using a Stored Proc but for some reason it won't work

    When i run the Sproc in query analyser it seems to be ok with it but when i run the asp pages it lets me enter the info then when i submit it gives me the Too many Arguments Specified error

    here's the code for the proc

    CREATE PROCEDURE [dbo].[Toregister]

    (

    @firstname varchar(20),

    @lastname varchar(20),

    @address varchar(20),

    @town varchar(20),

    @county varchar(20),

    @postcode varchar(10),

    @telno varchar(10),

    @email varchar(20),

    @username varchar(20),

    @password varchar(20)

    )

    AS

    insert into t_user (firstname,lastname,address,town,county,postcode,telno,email,username,password)

    values (@firstname,@lastname,@address,@town,@county,@postcode,@telno,@email,@username,@password)

    GO

    and here's the code in my aspx file for adding the parameters

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click

    SqlCommand1.Parameters.Add("@firstname", txtFirstname.Text)

    SqlCommand1.Parameters.Add("@lastname", txtSurname.Text)

    SqlCommand1.Parameters.Add("@address", txtAddress.Text)

    SqlCommand1.Parameters.Add("@town", txtTown.Text)

    SqlCommand1.Parameters.Add("@county", txtCounty.Text)

    SqlCommand1.Parameters.Add("@postcode", txtPostcode.Text)

    SqlCommand1.Parameters.Add("@telno", txtTelno.Text)

    SqlCommand1.Parameters.Add("@email", txtEmail.Text)

    SqlCommand1.Parameters.Add("@username", txtUsername.Text)

    SqlCommand1.Parameters.Add("@password", txtPassword.Text)

    SqlConnection1.Open()

    SqlCommand1.ExecuteNonQuery()

    End Sub

    and just for good measure here's the result from the DB profiler when I run the asp

    exec [Toregister] @firstname = default, @lastname = default, @address = default, @town = default, @county = default, @postcode = default, @telno = default, @email = default, @username = default, @password = default, @firstname = N'Neil', @lastname = N'Patel', @address = N'28 my street, @town = N'mytown', @county = N'mycounty', @postcode = N'mypostcd', @telno = N'01234567890, @email = N'neil_pat@email.com', @username = N'neilpat', @password = N'neil'

    I really can't see where this is going wrong

    Anny suggestions welcome

  • I have not used ASP.NET so if this seems a silly question please forgive me.  Have you tried CREATEPARAMETER 1st telling the system which direction the parameter is and of what type and THEN assigning the PARAMETER the values you want?

    EXAMPLE that I have used in VB

     '' Starts the definition of the Command object to execute SQL stored-procedure

      With adoCmd

        .ActiveConnection = cADOConn.Connection

        .CommandText = "dbo.usp_xxxxxxxxxxxxxxx"

        .CommandType = adCmdStoredProc

        Set adoParams = .Parameters

      End With

      '' Defines the ADO parameters for use by the stored-procedure

      With adoParams

        .Append adoCmd.CreateParameter("@RETURN_VALUE", adInteger, adParamReturnValue, 0)

        .Append adoCmd.CreateParameter("@RecordDate", adChar, adParamInput, 10)

        .Append adoCmd.CreateParameter("@TimeSystemID", adInteger, adParamInput, 1)

        .Append adoCmd.CreateParameter("@RecordType", adChar, adParamInput, 1)

        .Append adoCmd.CreateParameter("@Location", adInteger, adParamInput, 4)

        .Append adoCmd.CreateParameter("@MachineName", adVarChar, adParamInput, 255)

        .Append adoCmd.CreateParameter("@UserID", adVarChar, adParamInput, 255)

      End With

      '' Populates the parameters with data

      adoParams("@RecordDate") = Calendar1.Value

      adoParams("@TimeSystemID") = frmMain.cboTimeSystemID.ListIndex

      adoParams("@RecordType") = vRecordType

      adoParams("@Location") = frmMain.txtLocation

      adoParams("@MachineName") = vMachineName

      adoParams("@UserID") = vDomain & "\" & vUserLoggedIn

      '' EXECUTE Updating the system

      adoCmd.Execute

      adoParams("@RETURN_VALUE") = adoCmd.Parameters("@RETURN_VALUE")

    Also when you are done do you clean up the parameters collection? I.E. something like..

    Dim i As Integer

      '' USES Step -1 to delete last parameter and down.  This is the only way to _

        delete parameters (Highest number to lowest).  This collection is a 0 based array.

      With adoParams

        For i = .Count To 1 Step -1

          .Delete (i - 1)

        Next

      End With



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • I've managed to sort the problem now.

     

    VS.Net was trying ot add parameters by default automatically so i had 2 sets of parameters being input to the db

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply