Discussion Locked

Passing parameters from VB6 to SQL

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Dim intVal as Integer
intval = 2020
qconn.Execute("Select * from Table1 where userid=intval")

The question is how can I make sql recognize or accept intval as a predefined variable in VB6 and run the query with resultset based on the value of intval?

5 replies

by dennis.keeling

You need to ensure that the substitution takes place before the statement is executed.

"SELECT * FROM Table1 WHERE [UserID} =" & intval

by dragon emperor

Dim intVal as Integer
intval = 2020
qconn.Execute("Select * from Table1 where [userid]=" & CStr(intval))

As an alternative you could use a command object with parameters, but the above is the simplest to get the result you want.

This discussion is closed to new replies.