Stored Procedure/Parameter problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ElmoWatson

    #1

    Stored Procedure/Parameter problem

    I'm getting an error I don't understand....

    Here's my Code:


    Dim dr As SqlDataReader
    Dim retVal As Boolean = False
    Dim MySQL as string = "spGetEmplo yee"
    Dim Myconn as New
    SQLConnection(C onfigurationSet tings.AppSettin gs("EmpLogin") )
    Dim Cmd as New SQLCommand(MySQ L, MyConn)
    cmd.CommandType =CommandType.St oredProcedure
    cmd.parameters. add(New SQLParameter("@ Login", txtUID.text))
    cmd.parameters. add(New SQLParameter("@ Password", txtPWD.text))
    cmd = New SqlCommand(MySQ L, MyConn)
    MyConn.Open()
    dr = cmd.ExecuteRead er()

    But on that last line (executeReader) , I get this error:
    Procedure 'spGetEmployee' expects parameter '@Login', which was not supplied

    What am I doing wrong?


  • Jerry

    #2
    Re: Stored Procedure/Parameter problem


    Marina is correct. You can also just comment out cmd = New SqlCommand(MySQ L,
    MyConn)
    line of code.


    "Marina" <zlatkinam@nosp am.hotmail.com> wrote in message
    news:u5FMYcqWDH A.1640@TK2MSFTN GP10.phx.gbl...[color=blue]
    > When you say: cmd = new SqlCommand(MySQ L,MyConn), this creates a new
    > SqlCommand object.
    >
    > All the parameters you set before, just got wiped out, because the object
    > you set it on, no longer exists.
    >
    > Move the parameter statements to after this constructor call.
    >
    > "ElmoWatson " <sputnik75043@y ahoo.com> wrote in message
    > news:%23XPL9aqW DHA.2424@TK2MSF TNGP12.phx.gbl. ..[color=green]
    > > I'm getting an error I don't understand....
    > >
    > > Here's my Code:
    > >
    > >
    > > Dim dr As SqlDataReader
    > > Dim retVal As Boolean = False
    > > Dim MySQL as string = "spGetEmplo yee"
    > > Dim Myconn as New
    > > SQLConnection(C onfigurationSet tings.AppSettin gs("EmpLogin") )
    > > Dim Cmd as New SQLCommand(MySQ L, MyConn)
    > > cmd.CommandType =CommandType.St oredProcedure
    > > cmd.parameters. add(New SQLParameter("@ Login", txtUID.text))
    > > cmd.parameters. add(New SQLParameter("@ Password", txtPWD.text))
    > > cmd = New SqlCommand(MySQ L, MyConn)
    > > MyConn.Open()
    > > dr = cmd.ExecuteRead er()
    > >
    > > But on that last line (executeReader) , I get this error:
    > > Procedure 'spGetEmployee' expects parameter '@Login', which was not[/color]
    > supplied[color=green]
    > >
    > > What am I doing wrong?
    > >
    > >[/color]
    >
    >[/color]


    Comment

    Working...