Page 1 of 1

Database questions

Posted: Mon Mar 07, 2005 11:50 am
by David
Hi.

I am switching from VB to PB but I am having trouble understanding how you retrieve data from access databases in PB. For example, is there a PB equivalent for the following snippet?

-------------------------------

Set oRS = New Recordset
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0" & ";Data Source=" & App.Path & "\Database.mdb"
strSQL = "SELECT Field FROM Table"
oRS.Open strSQL, strConnect, adOpenForwardOnly, adLockReadOnly
Do Until oRS.EOF
If Len(oRS.Collect("Field")) > 0 Then
lstListBox.AddItem oRS.Collect("Field")
End If
oRS.MoveNext
Loop
oRS.Close
Set oRS = Nothing

-------------------------------

I won't ask too many questions here while I am learning but this would be very helpful. Thank you.

Posted: Mon Mar 07, 2005 11:56 am
by GedB
Take a look at Database.pb in the Examples\sources folder.

One major restriction is that you can only access a database through a DSN. You cannot use a connection string in your code.

You create DSNs in the control panel's data sources. The example program opens the data source dialog for you.

Posted: Mon Mar 07, 2005 1:34 pm
by David
Yes, that works ok. Thank you GedB.