I have an SQLite database included into my xojo project. I have created a webpage with a popupmenu and I would like to get the values from a table in my SQLite DB to show them when I select the popupmenu. I have created an ‘open’ event handler and I include this code:
[code]If DB.Connect = true then
Dim rs As RecordSet = DB.SQLSelect("Select StdServices.ServiceName From StdServices")
If rs <> nil and rs.RecordCount > 0 then
While not rs.EOF
Me.AddRow ("")
rs.MoveNext
Wend
rs.Close
End if
End if[/code]
Where is the error in my code? Could anyone help me?
Dim rs As RecordSet = DB.SQLSelect("Select StdServices.ServiceName From StdServices")
if DB.error then
msgbox DB.errormessage
return
end
If rs <> nil and rs.RecordCount > 0 then
While not rs.EOF
Me.Addrow rs.Field("ServiceName").StringValue
rs.MoveNext
Wend
rs.Close
End if
Open event should work. You can simplify the code as shown below since if there are no records (i.e. record count = 0) rs.eof will be set to true.
[code]If DB.Connect = true then
Dim rs As RecordSet = DB.SQLSelect("Select StdServices.ServiceName From StdServices")
if DB.error then
msgbox DB.errormessage
return
end
While not rs.EOF
Me.Addrow rs.Field("ServiceName").StringValue
rs.MoveNext
Wend
rs.Close
I made one change where I removed the “DB” object from the project, and loaded it dynamically in the App.Open event. Works fine then. I do not add databases to my projects like you did so I’m not sure why it’s not working like you wanted.
Thanks Bob, It’s true, your example works perfectly. I am newbie with Xojo and I will study your example to connect to my database like you. I don’t understand why it doesn’t work selecting an existing DB but I’m sure that your option it’s better… and works.
You might find a subscription to my Xojo training videos to be useful. We have over 60 hours of Xojo videos (about 200 videos and most come with project files) at show a lot of how we do things in Xojo (been doing this for about 15 years). http://xojo.bkeeney.com/XojoTraining/. We have a couple of start to finish desktop projects and one complete start to finish web application.
Thank Bob, I have already seen your subscription to your training videos. The price is reasonable but in this moment I cannot do this spending maybe the next year. I think so that firstly it’s better I get to know Xojo to take full advantage of your subscription.