While executing the following code in ASP.NET with VB, I am getting the error "No data exists for the row/column."

Dim hdnuserid = e.CommandArgument
    If e.CommandName = "additem" Then

        ' First, see if the product is already in the vendor_catalog table

        Dim dr, dr2, username
        dr = connection.returnsqlresult("SELECT * FROM vendor_users where vendor_id = '" & Request("vendor_id") & "' AND userid = '" & hdnuserid & "'")
        If dr.hasrows() Then
            dr.read()
            Response.Write("<script type=""text/javascript"">alert(""User already assigned to this vendor."");</script>")

        Else
            dr2 = connection.returnsqlresult("SELECT * FROM users WHERE userid = '" & hdnuserid & "'")
            Response.Write(hdnuserid)
            If dr2.hasrows() Then
                dr2.read()
                username = dr("username")
                connection.executesql("INSERT INTO vendor_users(userid, vendor_id, username) VALUES('" & hdnuserid & "','" & Request("vendor_id") & "','" & username & "')")
                'ScriptManager.RegisterStartupScript(Me, GetType(Page), "itemsadded", "window.opener.__doPostBack('__Page', 'populate_usergrid');window.close();", True)
            Else
                Response.Write("<script type=""text/javascript"">alert(""User does not exist."");</script>")

            End If
            dr2.close()
        End If
        dr.close()
    Else

    End If

I have checked that the columns exist in my tables, and also checked the select * from users statement in SQL directly with a hard coded value and I see the result I expect. I'm not sure why I am getting this error. The error is being thrown on the username = dr("username") line.

Any assistance in this would be very helpful.

JV

Related posts

Recent Viewed