Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Nov 16, 2018 9:44 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: List tables in combobox
PostPosted: Sun Jan 20, 2013 1:47 pm 
Offline

Joined: Fri Sep 18, 2009 8:09 am
Posts: 115
Location: Netherlands
This is what I want to do:
- open a database
- list the tables of the database in a combobox.

This is what I have so far.

Dim db As REALSQLdatabase
Dim TargetFile As FolderItem
Dim blnResult As Boolean
db = New REALSQLdatabase
TargetFile = GetOpenFolderItem("")
db.DatabaseFile = TargetFile
blnResult = db.Connect()
If blnResult = True Then
db.Close
Else
MsgBox "Database Error: " + db.ErrorMessage
End If

Dim tables As RecordSet
tables = db.TableSchema
dim ComboBox1 as combobox

If tables <> Nil Then
While Not tables.EOF
if tables.IdxField(1).StringValue <> "" then
combobox1.AddRow(tables.IdxField(1).StringValue)
end if
tables.MoveNext
Wend
tables.Close
End If


The only problem is that it doesn't work, the combobox stays empty. What can i do to make it work?


Top
 Profile  
Reply with quote  
 Post subject: Re: List tables in combobox
PostPosted: Sun Jan 20, 2013 2:03 pm 
Offline
User avatar

Joined: Fri Jun 05, 2009 11:50 am
Posts: 348
Location: Hamburg, Germany
Dont know if the rest works, but this snipped closes the db connection before you query the table names

blnResult = db.Connect()
If blnResult = True Then
db.Close
Else
MsgBox "Database Error: " + db.ErrorMessage
End If


in the true case you close the db connection, and the db.tableschema is nil

And are you creating combobox1 in code?

If you have combobox1 placed on window, you dont need to dim it

The following code works for me with the code placed in the action event of a pushbutton and a combobox1 placed on window

Dim db As REALSQLdatabase
Dim TargetFile As FolderItem
Dim blnResult As Boolean
db = New REALSQLdatabase
TargetFile = GetOpenFolderItem("")
db.DatabaseFile = TargetFile
blnResult = db.Connect()
If blnResult = True Then
//db.Close
Else
MsgBox "Database Error: " + db.ErrorMessage
End If

Dim tables As RecordSet
tables = db.TableSchema
//dim ComboBox1 as combobox

If tables <> Nil Then
While Not tables.EOF
if tables.IdxField(1).StringValue <> "" then
combobox1.AddRow(tables.IdxField(1).StringValue)
end if
tables.MoveNext
Wend
tables.Close
End If


I commented out the db.close and the dim combobox1 line

Using the debug mode (breakpoint on " If tables <> Nil Then"), you would have recognized, that tables is NIL :-) )

AND one should always check db.error after ANY db action (although in this case it would not help)

_________________
Best regards

Stefan

Mac OSX Mountain Lion (latest Release) on a MacBook Pro 2.66 GHz Intel Core i7/ RB Professional 2011 Release 3


Last edited by elChupete on Sun Jan 20, 2013 2:08 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: List tables in combobox
PostPosted: Sun Jan 20, 2013 2:05 pm 
Offline

Joined: Fri Sep 18, 2009 8:09 am
Posts: 115
Location: Netherlands
Working great. thanks!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group