Create a data source for data binding by adding a data environment.

Source: Internet
Author: User

Data Binding is an important data access function of Visual Basic. It associates a control with a specific field of the data source (usually a record set) and enables the control to automatically display data from the data source when the program is running, data modifications can also be automatically saved. Data sources used for data binding can be obtained using the ADO data control, or by creating a recordset object in the Code, or by using the data environment. This article focuses on creating a data source for data binding by adding a data environment.

Data environment is a brand new concept proposed by Visual Basic. The data environment designer provides an interactive design environment for accessing databases, allowing you to quickly and intuitively create database connection programs. It can combine many independently used objects and controls into a separate environment. After the establishment, this data environment can be used to access any database, query or add to the stored procedures. I will not talk much about it. Next we will go into the topic.

Before creating a data environment designer, you need to insert a sentence, which is also a key step, that is, do not forget to reference "Microsoft Data Environment 1.0 ", it can be implemented in "project"/"Reference. In the "project"/"add data environment" command, you can add a data environment designer for the project, the following "designer" folder appears in the "Project Resource Manager" window.

Double-click. In this case, a connection object is automatically added to the data environment designer, and the following form is displayed.

Set the connection property. Right-click connection1-"attribute" command. Select the corresponding program and database in "provider" and "connection. Then, "test the connection" to ensure the connection is correct, and then click "OK ". Right-click conncection1-"add command" to create the command object associated with the connection object to the data environment designer. Set the properties of the command object. Right-click the command object and select "properties". Set "Data Source" and "record set management" (that is, "common" card and "advanced" card), as shown in.

Oh, by the way, it is very important not to forget to set the attributes of datasource, datafield, and datamember. If you forget the settings, the program cannot run. When setting the Data Binding attribute of the text box, you must first set the datasource attribute, then set the datamember attribute, and finally set the datafield attribute. In the list, the order is from bottom to top. The following uses the data binding attribute image in the "user name" text box as an example.

Finally, this problem was found during programming.

Why should "Rs" be added before the command object? Why is it not a simple command object? Originally, the data environment designer could not create a recordset object separately. You can set it in "record set management" of the command object. The recordset object name starts with "Rs" and is followed by the name of the command object.

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.