6
Database connectivity using ADO (ActiveX data Object) 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 f rom 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 f orm. 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.  

Database Connectivity Using ADODC

Embed Size (px)

Citation preview

Page 1: Database Connectivity Using ADODC

8/8/2019 Database Connectivity Using ADODC

http://slidepdf.com/reader/full/database-connectivity-using-adodc 1/6

Database connectivity using ADO (ActiveX data Object)

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. 

Page 2: Database Connectivity Using ADODC

8/8/2019 Database Connectivity Using ADODC

http://slidepdf.com/reader/full/database-connectivity-using-adodc 2/6

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.

Page 3: Database Connectivity Using ADODC

8/8/2019 Database Connectivity Using ADODC

http://slidepdf.com/reader/full/database-connectivity-using-adodc 3/6

 

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.

Page 4: Database Connectivity Using ADODC

8/8/2019 Database Connectivity Using ADODC

http://slidepdf.com/reader/full/database-connectivity-using-adodc 4/6

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.

8 .) Run the form by pressing F5 key.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Page 5: Database Connectivity Using ADODC

8/8/2019 Database Connectivity Using ADODC

http://slidepdf.com/reader/full/database-connectivity-using-adodc 5/6

The program codes for add, delete, cancel, movefirst, movelast, next, previous

operations on click event of command buttons are as follow:

Private Sub cmdSave_Click()

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

======================

Private Sub cmdAdd_Click()

ADODC1.Recordset.AddNew

End Sub

=====================

Private Sub cmdDelete_Click()

ADODC1.Recordset.Delete

End Sub

 

======================================  

Private Sub cmdCancel_Click()

Text1.Text = ""

Text2.Text = ""Text3.Text = ""

Text4.Text = ""

Text5.Text = ""

End Sub

Page 6: Database Connectivity Using ADODC

8/8/2019 Database Connectivity Using ADODC

http://slidepdf.com/reader/full/database-connectivity-using-adodc 6/6

For the Previous (<) button, the program codes are

Private Sub cmdPrev_Click()

ADODC1.Recordset.MovePrevious

 

End Sub

===================

For the Next(>) button, the program codes are

Private Sub cmdNext_Click()

ADODC1.Recordset.MoveNext

 

End Sub

=================

Private Sub cmdFirst_Click()

ADODC1.Recordset.MoveFirst

 

End Sub

================

Private Sub cmdLast_Click()

ADODC1.Recordset.MoveLast

 

End Sub