Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameter not supplied?

Status
Not open for further replies.

tsp1lrk72

IS-IT--Management
Feb 25, 2008
100
US
This is driving me nuts... I can't seem to figure out what is wrong with this, I keep getting: Prepared statement '(@VendorID int)Select VI.VendorID, VI.DivisionName, VI.DeptName,' expects parameter @VendorID, which was not supplied. "

Code:
 Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Define connection to read the data 
        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
        Dim MyCmd As New SqlCommand("Select VI.VendorID, VI.DivisionName, VI.DeptName, VI.VendorCode, VI.VendorName, VI.Responsibility, VI.Joined, VI.SKU, VI.EDI, VI.RBT, VI.ContactName, VI.ContactPhone, VI.ContactFax, VI.EmailAddress, VM.Comment, VS.Status From tblVendorInfo VI Join tblVendorComments VM On VI.VendorID = VM.VendorID Join tblVendorStatus VS On VI.CurrentStatus = VS.StatusID Where VendorID = @VendorID", myConn)
        MyCmd.CommandType = CommandType.Text
        MyCmd.Parameters.Add(New SqlParameter("@VendorID", SqlDbType.Int, 4)).Value = Convert.ToString(VendorID)
        myConn.Open()
        'Read the data
        Dim Result As SqlDataReader = MyCmd.ExecuteReader(CommandBehavior.CloseConnection)
        Result.Read()
        VendorNumber.Text = Result("VendorID").ToString()
        If Not Result.IsDBNull(0) Then
            DivisionName.Text = Result("DivisonName").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            DeptName.Text = Result("DeptName").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            VendorName.Text = Result("VendorName").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            Joined.Text = Result("Joined").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            SKU.Text = Result("SKU").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            EDI.Text = Result("EDI").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            Rbt.Text = Result("RBT").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            ContactName.Text = Result("ContactName").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            ContactPhone.Text = Result("ContactPhone").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            ContactFax.Text = Result("ContactFax").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            EmailAddress.Text = Result("EmailAddress").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            Comment.Text = Result("Comment").ToString()
        End If
        myConn.Close()
    End Sub
Thanks...
already posted to SQL forum, they told me to come here...
 
Add a breakpoint and see if your VendorID variable is set to nothing when you assign it's value to your parameter.
 
split this up

MyCmd.Parameters.Add(New SqlParameter("@VendorID", SqlDbType.Int, 4)).Value = Convert.ToString(VendorID)

into this

MyCmd.Parameters.Add(New SqlParameter("@VendorID", SqlDbType.Int, 4))
MyCmd.Parametes(0).Value = Convert.ToString(VendorID)

Christiaan Baes
Belgium

My Blog
 
Oh and don't convert to string.

MyCmd.Parameters.Add(New SqlParameter("@VendorID", SqlDbType.Int, 4))
MyCmd.Parametes(0).Value = VendorID

Christiaan Baes
Belgium

My Blog
 
Hi Christiann--
Got the same thing... this is driving me nuts-- I can't set a breakpoint, I get failures with the debugging for some reason on this app--

Any other ideas?

Thanks
 
MyCmd.Parameters.Add(New SqlParameter("@VendorID", SqlDbType.Int))
MyCmd.Parametes(0).Value = VendorID

try that.

Althought the previous ones should have worked to.

What happes if you try the sql in queryanalyser?



Christiaan Baes
Belgium

My Blog
 
Works in query analyzer just fine... I added the VI.Vendor- no dice, same thing... it has to be something easy...UGH!!!
 
Since you are having problems debugging, try this:

MyCmd.Parameters.Add(New SqlParameter("@VendorID", SqlDbType.Int, 4))
MyCmd.Parameters("@VendorID").Value = VendorID

MsgBox("@VendorID = " & MyCmd.Parameters("@VendorID").Value)

This will tell you if the parameter's value is being assigned correctly.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
When I hardcoded a vendor id, it worked, it doesn't like the parameter? WHY?????

Code:
 Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Define connection to read the data 
        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
        Dim MyCmd As New SqlCommand("Select VI.VendorID,VI.DivisionName, VI.DeptName, VI.VendorCode, VI.VendorName, VI.Responsibility, VI.Joined, VI.SKU, VI.EDI, VI.RBT, VI.ContactName, VI.ContactPhone, VI.ContactFax, VI.EmailAddress, VM.Comment, VS.Status From tblVendorInfo VI Join tblVendorComments VM On VI.VendorID = VM.VendorID Join tblVendorStatus VS On VI.CurrentStatus = VS.StatusID Where VI.VendorID = @VendorID", myConn)
        'Dim MyCmd As New SqlCommand("Select VendorID,DivisionName,DeptName FROM tblVendorInfo Where VendorID = @VendorID", myConn)
        MyCmd.CommandType = CommandType.Text
        MyCmd.Parameters.Add(New SqlParameter("@VendorID", SqlDbType.Int, 4)).Value = Convert.ToString(VendorID)
        myConn.Open()
        'Read the data
        Dim Result As SqlDataReader = MyCmd.ExecuteReader(CommandBehavior.CloseConnection)
        Result.Read()
        VendorNumber.Text = Result("VendorID").ToString()
        If Not Result.IsDBNull(0) Then
            DivisionName.Text = Result("DivisionName").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            DeptName.Text = Result("DeptName").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            VendorCode.Text = Result("VendorCode").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            VendorName.Text = Result("VendorName").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            Joined.Text = Result("Joined").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            SKU.Text = Result("SKU").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            EDI.Text = Result("EDI").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            Rbt.Text = Result("RBT").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            ContactName.Text = Result("ContactName").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            ContactPhone.Text = Result("ContactPhone").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            ContactFax.Text = Result("ContactFax").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            EmailAddress.Text = Result("EmailAddress").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            Comment.Text = Result("Comment").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            CurrentStatus.Text = Result("Status").ToString()
            myConn.Close()
        End If
    End Sub

If I put =1 rather than @VendorID and take away this line:
MyCmd.Parameters.Add(New SqlParameter("@VendorID", SqlDbType.Int, 4)).Value = Convert.ToString(VendorID)

It works-- why doesn't it like the parameter???

HELP!
 
did you do what jebenson asked you?

Did you leave out the donvert.tostring?

Christiaan Baes
Belgium

My Blog
 
okay, DUH on my part- I never defined my VendorID as QUERYSTRING- HELLO???

I put in:
VendorID = Request.QueryString("Vendor").ToString
upon page load... it works now..

Thank you all for all of your troubleshooting, sorry about that, I just missed it like a dope.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top