Monday, April 16, 2018

Find and add ADO Data (ADODC) component in vb6.0 easy tips

Find and add ADO Data (ADODC) component in vb6.0 easy tips

In visual basic 6.0, if you want to connect 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 code

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, go to "Project" menu in Visual Basic window. Find "Components.." option and click on it. 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

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. Click on ADO icon and drag it to Form1.

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

This will show "Use Connection String" option already selected. Press on "Build..." button from it, "Data Link Properties" window will appear containing many option’s list for different types of database connection.

Dynamically add data in Listview at run time

Suppose, you have MS-Access database with name "Test.mdb". For MS-Access database, select "Microsoft Jet 3.51 OLE DB Provider" or select "Microsoft Jet 4.0 OLE DB Provider" option. Then press "Next>>" button. 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.

Then click on "Test Connection" button. as well as clicking on it, it will show 'Test connection succeeded' message box. 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
3. Database Connection Code:
The following code describe, how to use connection string in VB form’s 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 control and its connection string in vb6.0 through SKOTechLearn Tips.

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

0 comments: