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.
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:
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.