DataGrid in VB6.0
DataGrid in VB6.0
The ADO (ActiveX Data Object) data control is the primary interface between a Visual Basic application and a
database. It can be used without writing any code at all!
ADO features
ActiveX Data Objects (ADO) is designed to be an easy-to-use application-level interface to any OLE DB
data provider, including relational and non-relational databases, e-mail and file systems, text and
graphics, and custom business objects, as well as existing ODBC data sources. Virtually all of the data
available throughout the enterprise is available using the ADO data access technology.
ADO is easy to use, language-independent, implemented with a small footprint, uses minimal network
traffic, and has few layers between the client application and the data source — all to provide
lightweight, high-performance data access.
Ease of use.
High performance.
Programmatic control of cursors.
Complex cursor types, including batch and server- and client-side cursors.
Ability to return multiple result sets from a single query.
Synchronous, asynchronous, or event-driven query execution.
Reusable, property-changeable objects.
Advanced recordset cache management.
Flexibility — it works with existing database technologies and all OLE DB providers.
Excellent error trapping.
The simple semantics of ADO and universal application mean minimal developer training, rapid
application development, and inexpensive maintenance.
Using Datagrid Control
DataGrid control is the not the default item in the Visual Basic control toolbox, you have to add it from the VB6 components. To add the DataGrid
control, click on the project on the menu bar and select components to access the dialog box that displays all the available VB6 components, as shown
in the diagram below. Select Microsoft DataGrid Control 6.0 by clicking the checkbox beside this item. Before you exit the dialog box, you also need
to select the Microsoft ADO data control so that you are able to access the database. Last, click on the OK button to exit the dialog box. Now you
should be able to see that the DataGrid control and the ADO data control are added to the toolbox. The next step is to drag the DataGrid control and
the ADO data control into the form.
Before you proceed , you need to create a database file using Microsoft Access. Here we create a database file to store the information of books and
we named the table book. Having created the table, enter a few records, as shown in Figure 26.3 below:
Figure 26.3
Next, you need to connect the database to the ADO data control. To do that, right click on the ADO data control and select the ADODC properties, the
following dialog box will appear.
Next click on the Build button and the Data Link Properties dialog box will appear (as shown Figure 26.4). In this dialog box, select the database file
you have created, in my case, the file name is books.mdb. Press test connection to see whether the connection is successful. If the connection is
successful, click OK to return to the ADODC property pages dialog box( as shown in Figure 26.4). At the ADODC property pages dialog box, click on
the Recordsource tab and select 2-adCmdTable under command type and select book as the table name, then click OK.
Figure 26.4: Data Link Properties
Figure 26.5: Property Pages
Finally you need to display the data in the DataGrid control. To accomplish this, go to the properties window and set the DataSource property of the
DataGrid to Adodc1. You can also permit the user to add and edit your records by setting the AllowUpdate property to True. If you set this property to
false, the user cannot edit the records. Now run the program and the runtime interface is shown in Figure 26.5 below: