-
Hi, I am new to VB database programming, and i have a question.
I use ADO, the connectionstring is OK, on the RecordSource , I choose 1_adCmdtext, then I input a SQL , such as
"select * from Person where person.ssn=S_ssn"
, it do not work,
here, S_ssn is a public variable, and I also tried such as "select * from person where person.ssn= "'&S_ssn'" "
, or something like that. it totally don't work. When I put a value("111111111") intead of a S_ssn, it works.
I want to know How to use a public variable on the Recordsource choice.
Any Suggestions are welcome!
velle
-
Correct Syntax
strSql = "SELECT * FROM Person WHERE ssn = ' " & S_ssn & " ' "
Look at the single and double quotes.
Cheers
Ray
-
Hi, thanks for your advice, I tried , there is no syntax error, however, no result is shown.
I don't use code to do that, and I just use the ADODC's property page, I put the SQL on the "RECORDSOURCE" under the "1_adcmdtext".
Is it ONLY can be done using code? not in the property page.
thanks
velle
-
Yep, using variables with your SQL statement needs to be done in code at run-time. The property pages won't recognize variables.