Mysql - Row to Textfields


I was trying to do converting sqlite query command into mysql,
I want to show the row field into a textfield. I am using the sample msql sample database.

dim rs as RecordSet rs=mDB.SQLSelect("SELECT * FROM team WHERE ID = '"+ me.Cell(me.ListIndex, 0) +"'") TextField1.Text = rs.Field("ID").StringValue TextField2.Text = rs.Field("name").StringValue rs.close

What I got is NilObjecexception

any help ?


First, don’t do this, use a Prepared Statement.

Second, where exactly is the NilObjectException happening?

the error comes from this line,

TextField1.Text = rs.Field("ID").StringValue

The database is connected, and listed already in the listbox.
while I click the row of listbox, its shows this NilObjectException error.

I am expecting that the row and column value shows in the textfields.

its used to works before, i dont know why.


After the SELECT you need to test for mDB.Error and then for the rst being Nil before accessing the values of the first record.

try so

dim rs as RecordSet
rs=mDB.SQLSelect(“SELECT * FROM team WHERE ID = '”+ me.Cell(me.ListIndex, 0) +"’")

if rs <> nil then
if rs.RecordCount = 1 then
TextField1.Text = rs.Field(“ID”).StringValue
TextField2.Text = rs.Field(“name”).StringValue
end if
if mDB.Error= true then
MsgBox mDB.ErrorMessage
end if
end if


I putting db.error message,
The result is weird.

Its says that the table ‘admin_dbtest’ is missing, but actually the table name is ‘team’ and admin_dbtest is the mysql database name.

The mysql is connected, the row is populated on the list box, but when it clicked, the error is shown.


A recordset is usually only NIL if the SQL statement was malformed… OR if there was no connection to the database … and that is what sounds likely here…

Did you add error checking at the point you are attempting to connect to the database?
Are you sure the connection is no going out of scope? (a common error these days it seems)

what is exactly inside me.Cell(me.ListIndex, 0) ?
best way to get it is to msgbox me.Cell(me.ListIndex, 0)

is the value of column 0 in a listbox. and the value is Row ID.

Note : I am doing testing with online mysql on a vps.


in how listbox event you put the code

This code is placed in listbox event ‘change’.

What i did is, just tried to follow the mysql sample project without any modification.