Database Connectivity Using ADODC
Database Connectivity Using ADODC
To be able to access and manage a database, you need to connect the ADO data control to
a database file. We are going to use BIBLIO.MDB that comes with VB6. To connect ADO to
this database file, follow the steps below:
1.) Open a new VB project and from the Components window (by clicking Project -> Components
menu), select Microsoft Activex Data Control 6.0 (OLEDB) and click OK. ADO data control will
appear in the toolbox.
2.) From toolbox, Drag & Drop Activex Data object data control (ADODC1) on your form.
3.) Click on the ADO control on the form and it will open the properties window.
4.) Click on the General tab and check the ConnectionString property
When the dialog box appears, select the Use Connection String's Option. Next, click build command
button and at the Data Link Properties window, double-Click the option Microsoft Jet 3.51 OLE DB
provider.
After that, click the Next button to select the database name BIBLO.MDB. You can click on
Test Connection button to ensure proper connection of the database file. A messagebox will
appear, Click OK to finish the connection.
5.) Finally, click on the RecordSource property and set the command type to adCmd
Table and Table name to Customers. Now you are ready to use the database file.
6.) Drag & Drop a Textbox control (Text1) on your form, and set the properties as follows:
Property Value
DataSourceName Select ADO data control name: ADODC1
DataField Select field of table to be displayed: CustomerID
7.) Now repeat the above step for all other text boxes on the form to set their DataSource, and
DataField properties.
ADODC1.Recordset.Fields("Title") = txtTitle.Text
ADODC1.Recordset.Fields("Year Published") = txtPub.Text
ADODC1.Recordset.Fields("ISBN") = txtISBN.Text
ADODC1.Recordset.Fields("PubID") = txtPubID.Text
ADODC1.Recordset.Fields("Subject") = txtSubject.Text
ADODC1.Recordset.Update
End Sub
======================
ADODC1.Recordset.AddNew
End Sub
=====================
ADODC1.Recordset.Delete
End Sub
======================================
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub
ADODC1.Recordset.MovePrevious
End Sub
===================
For the Next(>) button, the program codes are
ADODC1.Recordset.MoveNext
End Sub
=================
ADODC1.Recordset.MoveFirst
End Sub
================
ADODC1.Recordset.MoveLast
End Sub