working-with-vb6-databases

In this tutorial, I will show you how to connect Visual Basic 6 to Microsoft Access using ADODC control.

Here our database will contain three data fields. Name, Number and City and our VB6 project will contain three TextBoxes to display the data.

Our final project will look like this:

working-with-vb6-databasesStep 1: Run Visual Basic 6Step 2: Select Standard EXE and OPEN

working-with-vb6-databasesStep 3: Right click anywhere in the Toolbox and select Components

working-with-vb6-databases

Step 4: In the components window, under controls tab find “Microsoft ADO Data Control 6.0 (OLEDB)” and select and tick the box, click Apply then OK.

After clicking “OK” the ADODC tool will be added to your VB6 ToolBox

working-with-vb6-databasesNow that we have added the ADODC control, we have to connect it to our database file. To do so follow the steps below..We are using Microsoft Access 2013 for our database.

Step 5:  Open Microsoft Access 2013 — select blank desktop — name your database whatever you want — click Create

Note: Always save your database as .mdb (2002 – 2003 file format) whenever you are working with VB6

working-with-vb6-databasesStep 6: Go to Create tab and select Table Design

working-with-vb6-databasesStep 7: Type Field Name (Field name is the column name, under which we will add our data) and select Data Type

Here I am adding three fields “Name” , “Number” and “City”.

working-with-vb6-databasesStep 8: Select File and Save. A “Save as” window will pop up — click Ok.

working-with-vb6-databasesAfter clicking “Ok” MSAccess will throw a warning message “There is no primary key defined”. Select NO

working-with-vb6-databasesStep 9: Double click on table name and enter the data. (Later we will add data from VB6)

working-with-vb6-databasesAfter adding data save the file and exit.

Now we will connect this table to our VB6 ADODC control

Step 10: Select the ADODC control (which you have already created on the VB6 form ) and from the properties window, select ConnectionString

working-with-vb6-databasesStep 11: The Property page window will open. Select Build

working-with-vb6-databasesStep 12: After clicking Build, the Data Link Properties window will open.

Now under Provider tab select Microsoft Jet 4.0 OLE DB Provider and click on Next

Step 13: Under Connection tab browse and select your database file (.mdb) and click Ok

working-with-vb6-databasesYou have successfully connected your database file with VB6 ADODC control.

Step 14: 
Again select the ADODC control and from the properties window, select RecordSource 

working-with-vb6-databasesStep 15: On the “Property pages” window, select Command Type (2- ad CmdTable) and Table or Stored Procedure Name (See the below image)

working-with-vb6-databases

Now that everything related to connection is complete, we have to display the contents of the database file.

Step 16: Here I am creating three TextBoxes and three labels

working-with-vb6-databasesStep 17:Select a TextBox and select DataSource and then DataField. 

working-with-vb6-databases

 

working-with-vb6-databasesDo the same for Text3.

Now click Start and see the final result.

working-with-vb6-databases

Databases in Visual Basic 6 – ADODC – VB6
Tagged on:

Leave a Reply

Your email address will not be published. Required fields are marked *