If I am trying to write something that will allow me to take what is in the column id and what ever it is 0 or 1 or what ever number and match it to the username and fill out in the text fields I have setup the data from the id. Something like this.
if db.Connect Then
rs = db.SelectSQL("SELECT * FROM login_server WHERE id = ?", id.text)
Let say id is 0 for username: codeman I want the code to be able to fill out the username, name and all the information depending on what the id is but I do not know how to change the code to make it work not sure what I am missing or what I need to add.
It’s worth mentioning too that MySQL will return a “row” even if your Select Statement yields NO results. So in addition to checking if returned rows <> Nil, you should make sure to verify there are actual rows to act on.
Well see that is one of my issues even if I login with a different username the id stays 0 and does not change and not sure why because the next login name is id = 1 so not sure why it is not changing. The code seemed right to me but now I don’t know.
What I am saying though is I don’t think it has anything to do with the if statement because I think the sql call is wrong maybe because the number never changes from 0 it stays 0 and will not change from 0. Yes I am using integer. I think I have to change the sql statement but not sure what to make it work.
So you should not compare integer (in DB) with text/string in the Statement.
Or to say in SQL. You do:
select * from table where 1 = ‘1’;
As a result you get an empty recordset, so what you get is correct. Your Statement is wrong.
so something like:
rs = db.SelectSQL(“SELECT * FROM login_server WHERE id = ?”, id.integerValue)
If Not db.Connect Then Return
rows = db.SelectSQL("SELECT * FROM login_server WHERE id = ?", id)
If rows = Nil Or rows.Count = 0 Then Return
// Now handle the data
Catch err As DatabaseException
// Handle Database Errors
Well I can say for sure it is not nil because I send a messagebox for that and I also setup the number 0 for user codeman and it cannot be nil so I also check for that. but you have a point though I could add them as properties but even holding them into var should still do the same thing for the most part unless it is losing data but don’t think it is. I still think I have to be missing something with the sql statement for the reason it is not changing the id since the id is not null.
I am using .AddText because it is an array, and it will not let me use .Text without changing it. Yes, I changed it and yes id is an Integer. When I run the code it adds the values into each textfield when I login with codeman which his id is 0 and jsmith id is 1 but it does not post his information in the textfield nor does it change the id number to 1 which it should. The reason I am using the first action is because I wanted to see if the number would change, and it did not.