Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Nov 22, 1999

Linking a Listbox to a Database

Question:
How can I put a column from my database into a listbox using VB 6.0?

Answer:
Here's a quick way to load a listbox using ADO in VB 6.0. You'll have to connect to your database using the appropriate provider—the one shown here is using the Jet 4.0 provider for Access 97 and 2000. You'll need to substitute in the database name, the table name, and the field name.

Dim dcnDB As New ADODB.Connection
Dim rsData As ADODB.Recordset
dcnDB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Database.MDB"
Set rsData = dcnDB.Execute("SELECT Field FROM Table")
Do Until rsData.EOF
   ListBox1.AddItem rsData("Field")
   rsData.MoveNext
Loop
rsData.Close
dcnDB.Close
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date