excel - Problem with VBA script reading from MySql database -
i having trouble vba script in excel should reading mysql database. sql query should return 1 record returns empty resultset. generated statement works fine when run through phpmyadmin.
here code:
function getclientid(emailaddress string) dim rs adodb.recordset dim sql string connectdb set rs = new adodb.recordset sql = "select client_id clients email_address = '" & emailaddress & "' limit 1" debug.print sql rs.open sql, oconn debug.print rs.recordcount if (rs.recordcount = -1) getclientid = null else getclientid = rs(0) end if rs.close end function
edit: database connect function.
function connectdb() on error goto errhandler set oconn = new adodb.connection oconn.open "driver={mysql odbc 5.1 driver};" & _ "server=localhost;" & _ "database=mydb;" & _ "user=user;" & _ "password=password;" & _ "option=3" 'debug.print oconn exit function errhandler: msgbox err.description, vbcritical, err.source end function
the connectdb function connecting ok running other scripts it. if can see doing wrong appreciated.
many in advance.
garry
myodbc not provide recordcount-attribute.
re: problem recordcount asp & mysql
re: ado connection recordcount
so, if need recordcount, set cursorlocation property aduseclient. if not, iterate through recordset this:
do while not rs.eof '...do magic rs.movenext loop
Comments
Post a Comment