VB Tutorial: Display database records

Source: Internet
Author: User

VB Tutorial: Display database records

To display data in the database to the user, you must use a data constraint control, such as the text box used earlier and other common constraint Data Controls provided by VB, VB also provides a variety of advanced constraint data controls, including: Advanced constraint Data Grid Control (DBGrid), advanced constraint list control (DBList), and advanced constraint combo control (DBCombo ). These controls are not added to the default toolbox. to use them, you must reference them first: Right-click the toolbox and select "component", and click the "MicrosoftDataBoundGridControl" check box to add the grid control, click "MicrosoftDataBoundListControls5.0" to add the list control and combo control.

Advanced constraint Data Grid Control (DBGrid)

The advanced constraint Data Grid Control displays and allows operations on record set objects connected to it. The DBGrid control is called "data-aware, that is, you only need to set its DataSource attribute to the Data Control (of course, The DatabaseName and RecordSourse attributes of the Data control must be correctly set), and then you can use the record set to automatically fill in the control's grid, the column header is automatically set by the record set object.

In other words, we can see the structure and content of the entire record set visually through the two-dimensional mesh displayed by the DBGrid control. You can specify the current unit in the Code, or use the mouse or unit arrow to change the current unit at run time, and then modify the unit content. The unit can be selected separately or by row. You can use the Count attribute of the column Columns set of the DBGrid control and the RecordCount attribute of the Recordset object to determine the number of rows and Columns in the control.

The constraint data list control (DBList) and

Constraint data combo control (DBCombo)

DBList and DBCombo controls are controls that are connected to Data. They can automatically display the Field Values of the Data control that are connected to them in the list, you can also selectively update related table fields in other Data controls. The list of the DBList and DBCombo controls is automatically filled with Data items by setting the fields in the Recordset object of the Data control that are connected to the DBList and DBCombo controls, in addition, the control has the ability to update fields in the related Recordset objects of different Data controls, that is, using a field value in one record set to update the value of a field specified in another record set.

Common attributes of DBList and DBCombo:

· RowSource: The name of a Data Control used as the project Source of the Control List section. That is, a field in the specified Data control is used to fill the list area of the list control;

· ListField: a field name in the Recordset created by the Data Control specified by RowSource, used to fill the list;

· SelectedItem: bookmarks of the selected project in Recordset specified by the RowSource attribute (that is, the record of the selected field project ).

For example, if you select a person name in the list, all the complete information of the person is displayed in the other text boxes.

Start a new project, place a Data Control on the form, and set its DatabaseName to "c: myfile. mdb, RecordSource is set to "Phone" table; a DBList control sets RowSource to Data1 and ListField to "name"; three Text controls set DataSource to Data1, dataField is "name", "phone", and "Address" respectively ". Now we run the program and we will see the complete information in the first record. However, when you Click the list to select another project, no changes will occur because the list box control does not specify how to respond to the Click event, as a result, Data cannot be relocated to a new record that matches the clicked item in the record set. Therefore, add the following code to the Click Event of the list control:

Data1.RecordSet. Bookmark = DBList1.SelectedItem

The Bookmark attribute identifies a row in the record set. By setting this attribute, the Data control can locate a Specific Row. The SelectedItem attribute of the control is not the text displayed in the control editing box, but the record bookmarks to which the selected field belongs. This Code allows the Data Control in the record set to be relocated, and update the text box constraint Data Control on the form. ->

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.