Passing Query String Variable

The attached code is "supposed" to be getting the VendorId from a query string then used for a stored procedure.  The problem is that the the line below states "VendorId" is not declared.  I think I am doing something stupid, but I am missing it.  Thanks!

cmd.Parameters.Add("@VendorId", Data.SqlDbType.VarChar).Value = VendorId
Public Class VendorWebForm
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim OrdersProductKey As String
        Dim VendorId As String
        VendorId = Request.QueryString("VendorId")
        If (Request.QueryString("OrderProductKey") <> Nothing) Then
            OrdersProductKey = Request.QueryString("OrderProductKey")
            If Not IsPostBack Then
                LoadVendorOrderWebForm(Convert.ToString(Request.QueryString("OrderProductKey")))
            End If
        End If
    End Sub

    Private Sub LoadVendorOrderWebForm(ByVal OrdersProductKey As String)
        frmResBPO.DataSource = Nothing
        frmResBPO.DataBind()
        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim dt As New System.Data.DataTable
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.GetOrdersProductByOrdersProductKey"

            Dim iUserId As New Guid(Membership.GetUser(My.User.Name).ProviderUserKey.ToString())
            cmd.Parameters.Add("@OrdersProductKey", Data.SqlDbType.VarChar).Value = OrdersProductKey
            cmd.Parameters.Add("@VendorId", Data.SqlDbType.VarChar).Value = VendorId

            Dim adpt As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(cmd)
            cnn.Open()
            adpt.Fill(dt)

            frmResBPO.DataSource = dt
            frmResBPO.DataBind()


        Finally
            cnn.Close()
        End Try
    End Sub


End Class

Open in new window

rcowen00Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

appariCommented:
you declared VendorID in Page_load event and trying to use it in LoadVendorOrderWebForm procedure, that's not possible. Either declare VendorID within the sub LoadVendorOrderWebForm and set the value or declare VendorID as a page level variable. something like this:
        Dim VendorId As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim OrdersProductKey As String
        VendorId = Request.QueryString("VendorId")
        If (Request.QueryString("OrderProductKey") <> Nothing) Then
            OrdersProductKey = Request.QueryString("OrderProductKey")
            If Not IsPostBack Then
                LoadVendorOrderWebForm(Convert.ToString(Request.QueryString("OrderProductKey")))
            End If
        End If
    End Sub

Open in new window


or
Public Class VendorWebForm
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim OrdersProductKey As String
        Dim VendorId As String
        VendorId = Request.QueryString("VendorId")
        If (Request.QueryString("OrderProductKey") <> Nothing) Then
            OrdersProductKey = Request.QueryString("OrderProductKey")
            If Not IsPostBack Then
                LoadVendorOrderWebForm(Convert.ToString(Request.QueryString("OrderProductKey")))
            End If
        End If
    End Sub

    Private Sub LoadVendorOrderWebForm(ByVal OrdersProductKey As String)
        frmResBPO.DataSource = Nothing
        frmResBPO.DataBind()
        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim dt As New System.Data.DataTable
            Dim cmd As New System.Data.SqlClient.SqlCommand
            Dim VendorId As String
            VendorId = Request.QueryString("VendorId")

            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.GetOrdersProductByOrdersProductKey"

            Dim iUserId As New Guid(Membership.GetUser(My.User.Name).ProviderUserKey.ToString())
            cmd.Parameters.Add("@OrdersProductKey", Data.SqlDbType.VarChar).Value = OrdersProductKey
            cmd.Parameters.Add("@VendorId", Data.SqlDbType.VarChar).Value = VendorId

            Dim adpt As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(cmd)
            cnn.Open()
            adpt.Fill(dt)

            frmResBPO.DataSource = dt
            frmResBPO.DataBind()


        Finally
            cnn.Close()
        End Try
    End Sub


End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rcowen00Author Commented:
Worked great.  Can you explain why the other parameter was still able to work?  Thanks!
0
appariCommented:
the other one "OrdersProductKey" is passed as a parameter to the sub.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.