Find and Add ADO Data (ADODC) Component in VB6.0 easy tips

In visual basic 6.0, if you want to connect VB Form with Database or you want to access database connection. ADODC provide the simple way to connect any database, you can connect with MS-Access, SQL, Oracle, Excel, Text, CSV etc. In this post SKOTechLearn describe the process to find and add ADO data (ADODC) component in VB6.0.

You can learn about this component's features with simple and easy connection settings. This topic contains full explanations with examples. In this post, I will describe about some basic topic related to to this control.

  1. Find and Add ADODC Component
  2. Database Connection with ADODC
  3. Database Connection String Code In VB

Adding "Microsoft ADO Data Control 6.0 (OLEDB)" component in Toolbox, follow step by step instruction.

Connection with Login form and MS-Access in vb6.0

1. Find and Add ADODC Component:

First you have to add component on your VB Project:

1.
Go to "Project" menu in Visual Basic window. Find "Components.." option and click on it.

2.
Check on "Microsoft ADO Data Control 6.0 (OLEDB)" option from "Components" window, the press "OK" button.

There is another way to directly open "Components" window by pressing key (ctrl + T) from keyboard.

Steps:
Visual Basic (window)  Project  Components  Controls (Tab)  Microsoft ADO Data Control 6.0 (OLEDB)  Apply  OK

Note: If you cannot find "Microsoft ADO Data Control 6.0 (OLEDB)" option in "Controls" tab, click on "Browse.." button. Go to the location ("C:\windows\system32") and find "MSADODC.OCX" file. Select this file and click on "Open" button. This will add to "Controls" tab’s list.

Database record through ADODC in MSHFlexGrid

3.
After that, this component will be add to "ToolBox".

Add ADODC Component in Toolbox
Add Component

2. Database Connection with ADODC:

When adding this component to "Toolbox" will done.

4.
Click on ADO icon and drag it to Form1.

5.
Right click on this control and select "Properties" option from it, a "Property Pages" window will appear containing tabs (General, Authentication, RecordSource, Color, Font).

6.
This will show "Use Connection String" option already selected. Press on "Build..." button from it.

7.
It will present "Data Link Properties" window containing many option’s list for different types of database connection.

Dynamically add data in Listview at run time

8.
Suppose, you want to Connect MS-Access database with name "Test.mdb". Then you have to select "Microsoft Jet 3.51 OLE DB Provider" or select "Microsoft Jet 4.0 OLE DB Provider" option. Then press "Next>>" button.

9.
When clicking on "Next>>" button, it will jump in "Connection" Tab. This tab contain 2 categories.

1. Select or enter a database name: press "..." button. And select file like "Test.mdb" from that location.

2. Enter information to log on to the database: in this category, input password if database file is password protected otherwise check on “Blank password” check box.

10.
After that click on "Test Connection" button. as well as clicking on it, it will show 'Test connection succeeded' message box.

11.
Press "OK" button from this message box. Then click on "OK" button from "Data Link Properties" window. This will present "Use Connection String" option’s TextBox contain string value.

Listview data editing or deleting code in vb6.0

Steps:
ADODC (right click) ADODC Properties ➽ Build... (Click from "Use Connection String") ➽ "Microsoft Jet 3.51 OLE DB Provider" (select) ➽ "1. Select or enter a database name:" ➽ "Test Connection" ➽ OK (Click) ➽ Copy "Use Connection String" value

The following image describes step by step instruction.

ADODC component connection settings
ADO Data connection settings
So, this is the static way to Connect Database in VB6.0 through ADODC Properties Settings.

3. Database Connection String Code in VB :

The following code describe, how to use Database Connection String in VB Form’s Load events.

VB6.0 Code:
'global define cnn as connection of ADO data
Public cnn As New ADODB.Connection

Private Sub Form_Load()

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Test.mdb;Persist Security Info=False"

End Sub

So, by apply these given above steps, you can easily use ADODC Database Connection in VB6 and Adodc Connection String in VB6.0.

Column header and add data in MSHFlexgrid in VB6.0 code

1 comment:

  1. All of a sudden, after installing SQL Server 2000, I got some problem in my listview in vb 6.0 . the alignment options(left/center/right) is not there. and showing invalid property value.

    ReplyDelete