Procedure or function has too many arguments

  • Dear all,

    I have the following stored proc:-

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_NULLS OFF

    GO

    ALTER PROCEDURE dbo.stpLoginUser

    (

    @login Varchar(255),

    @password Varchar(255),

    @email Varchar(255) OUTPUT,

    @username Varchar(255) OUTPUT,

    @id int OUTPUT

    )

    AS

    BEGIN

    /*

    Check for valid login and password

    */

    SET @username = ' '

    Select @id = id_u, @username = first_name, @email = email from pod_Users where email = @login AND u_password = @password

    END

    GO

    SET QUOTED_IDENTIFIER OFF

    GO

    SET ANSI_NULLS ON

    GO

    and basically the user enters a username and a password.

    However I got the following error:-

    Procedure or function has too many arguments

    I tried renaming my stored proc name but to no avail.

    I am calling this stored proc from a vb.net program as follows:-

    Dim conn As SqlConnection

    Dim cmd As SqlCommand

    Dim RetVal As Integer = -1

    Dim FullName As String

    ' create the conection object for scalar reader to use

    conn = New SqlConnection

    conn.ConnectionString = ConnectionString

    ' return the players pk_player

    cmd = New SqlCommand

    cmd.CommandType = CommandType.StoredProcedure

    cmd.Connection = conn

    cmd.CommandText = "stpLoginUser"

    cmd.Parameters.Add("@login", SqlDbType.NVarChar, 255)

    cmd.Parameters("@login").Value = username

    cmd.Parameters.Add("@password", SqlDbType.NVarChar, 255)

    cmd.Parameters("@password").Value = password

    cmd.Parameters.Add("@username", SqlDbType.NVarChar, 255)

    cmd.Parameters("@username").Direction = ParameterDirection.Output

    cmd.Parameters.Add("@email", SqlDbType.NVarChar, 255)

    cmd.Parameters("@email").Direction = ParameterDirection.Output

    cmd.Parameters.Add("@id", SqlDbType.Int)

    cmd.Parameters("@id").Direction = ParameterDirection.Output

    Try

    conn.Open()

    cmd.ExecuteScalar()

    RetVal = cmd.Parameters("@id").Value()

    FullName = cmd.Parameters("@username").Value()

    'Catch

    Catch e As Exception

    Console.WriteLine(e.ToString()) ' Print the error message to the user.

    RetVal = -1

    Finally

    conn.Close()

    End Try

    Can anybody help me pls?

    Thanks for your help

  • can you remove the @ at

    cmd.Parameters.Add("@login", SqlDbType.NVarChar, 255) ...

    I guess ado adds it by itself.

  • Thanks I solved it like this:-

     

    conn =

    New SqlConnection

    conn.ConnectionString = ConnectionString

    ' return the players pk_player

    cmd =

    New SqlCommand

    cmd.CommandType = CommandType.StoredProcedure

    cmd.Connection = conn

    cmd.CommandText = "stpLoginUser"

    cmd.Parameters.Add("@login", SqlDbType.NVarChar, 255)

    cmd.Parameters("@login").Value = username

    cmd.Parameters.Add("@password", SqlDbType.NVarChar, 255)

    cmd.Parameters("@password").Value = password

    cmd.Parameters.Add("@id", SqlDbType.Int)

    cmd.Parameters("@id").Direction = ParameterDirection.Output

    conn.Open()

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

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