How can I use a Visual Basic variable into a SQL query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Visual Man
    New Member
    • Dec 2010
    • 1

    How can I use a Visual Basic variable into a SQL query?

    I used following code in one of my vb project:

    Dim PI As Integer
    PI = ProductIdtxt.Te xt
    rs.Open "select name,quantity_a vailable from product where product_id="&PI &"", db, 3, 1
    productNametxt. Text = rs.Fields(0)

    But it didn't work. It showed the following error messege

    Compile error:
    Expected:End of statement

    Please give me a solution.
    N.B.:I use Microsoft Visual Basic 6.0
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    Try this

    rs.Open "select name,quantity_a vailable from product where product_id=" & PI, db, 3, 1

    ??

    this assumes that db is a valid connection object

    MTB

    Comment

    Working...