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.ConnectionDim rsData As ADODB.RecordsetdcnDB.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.MoveNextLooprsData.ClosedcnDB.Close
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: