简体   繁体   中英

EXCEL(VBA) How to pass an sql query value into a variable?

I'm using MySQL and EXCEL(VBA) How can I pass an sql query value into a variable?

I have a variable Dim-ed:

Dim sqlVar As Variant

It's variant because I'm not sure which type I should use. I have set the sql query to the variable like this:

sqlVar = "SELECT datum FROM arfolyam ORDER BY datum ASC LIMIT 1 "

But like this, it stores the sql query, not the value of the query!

Any ideas?

...
Dim strSQL as String    
...
strSQL = "SELECT column FROM table ORDER BY column DESC LIMIT 1"
Set rs = cn.Execute(strSQL)   
variable1 = rs.Fields(0).Value      

This way the sql query's value which is in this case is one cell, will be given to the variable1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM