VB Prodigy Tutorial (continued)--a simple instance of connecting to access using the ADO Data control

Source: Internet
Author: User
Tags mdb database ole create database

This article welcomes the non-commercial use of reprint, but need to indicate from the "Programming Network" and the corresponding URL link.

The ADO Data control uses Microsoft ActiveX Data Objects (ADO) to quickly establish a connection between a data-bound control and a data provider. Although you can use ActiveX Data objects directly in your application, the ADO Data control has the advantage of being a graphical control ( With the forward and backward buttons, and an Easy-to-use interface that allows users to create database applications with minimal code. A data-bound control is any control that has a data source property. In the VB Toolbox, many controls can be used as data-bound controls, including check boxes, combo boxes, images, labels, list boxes, picture frames, and text box controls. In addition, VB includes several types of data-bound ActiveX controls, such as DataGrid, DataCombo, Chart, and DataList controls. Users can also create their own data-bound ActiveX controls, or use controls purchased from other developers. The data provider can be any data source that conforms to the OLE DB specification, and a class module using VB can also easily create a subset of data providers.

In the following program example, an ADO Data control and a DataGrid control are used, and the program executes as follows:

The DataGrid control displays and allows data manipulation of a series of rows and columns representing records and fields in a Recordset object, which is a data-bound ActiveX control. Each cell of the DataGrid control can contain text values, but not links or inline objects. You can specify the current cell in your code, or you can use the mouse or arrow keys to change it at run time. Cells can be edited interactively by typing or programmatically in a cell. Cells can be selected individually or by row.

Here we go to complete this program. First create a new Standard EXE project, and set the Form1 Caption property in the project to "Connect to a simple instance of access using the ADO Data Control", and the Width property value is set to 8490. Add 1 ADO Data controls to the form. If you cannot find the ADO Data control in the Toolbox, you can right-click the Toolbox, select the "part ..." menu item, and then in the Parts window, in the Controls tab, select Microsoft ADO data Control6.0 (OLE DB). Then add a DataGrid control to the Form1 and set its Width property value to 8055. If the control is not present in the Toolbox, you can right-click the Toolbox and select Microsoft DataGrid Control6.0 (OLE DB) in the Controls tab of the Parts window. When you are done, the following illustration shows:

Here we set some of the properties for these controls.

Set ADODC1:

(1) ConnectionString property

The ConnectionString property represents a ADODC1 connection string, and you can set the connection string properties in three ways, as shown in the following illustration. Here we select "Use ODBC data source name", and select access_db in the Drop-down box, click the OK button, you can see the string form of "dsn=access_db" in the ConnectionString property.

(3) RecordSource property

RecordSource property to set the recordset source, here we will enter the following SQL statement under the command text of the property page:

Select * from Wzdz ORDER by site name

By clicking the OK button, you can see the string form of the SELECT * from Wzdz ORDER by site name in the RecordSource property, as shown in the following figure:

Set the DataSource property for DataGrid1: The DataSource property specifies the data source for the control, which is set to the ADO Data control named "ADODC1", which returns all the records in the Web site Address table.

Run the program and you can see that the program has successfully connected to the Access_db.mdb database and that all the records in the "Wzdz" table are displayed in the DataGrid control.

Further, if you set the AllowAddNew, AllowDelete, and AllowUpdate properties of the DataGrid control to true individually, you can add, delete, and update records in the database at the time the program runs.

See a full set of "VB Prodigy Tutorials" (continued)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.