Wednesday, December 12, 2012

Data bound control in visual basic


The Data-Bound Controls: You can bind certain controls to the data control, the remote data control, and the ADO data control, and those controls are called bound controls. To bind a control to a database control, you use properties like DataSource to specify the database control, and then use properties like DataField or BoundColumn to specify what field to display in the bound control, as we’ll see. Here are the controls that can function as bound controls:
Picture boxes
Labels
Text boxes
Checkboxes
Image controls
OLE controls
List boxes
Masked edit controls
Rich text boxes
Combo boxes
In addition, there are special controls that are designed to be used as bound controls:
DBList
DBCombo
FlexGrid
MSFlexGrid
Finally, a number of bound controls are specially built to be used with the ADO control only:
DataList
DataCombo
DataGrid

Using Data Control:  
  1. Create a database using MSAccess, Oracle or Sql server named st_detail and a table student having fields (name, roll no, class).
  2. Start a new Standard EXE project and design a Form that looks like                       
  3. Start by drawing a Data control at the bottom of the Form. The Data control is your gateway to the database.
  4. With the Data control selected, locate its DatabaseName property, and set the path to st_detail database.
  5. Locate the RecordSource property in the Properties window, and drop down the list of available entries. You’ll see a list of all the tables in the st_detail database. Select the student table.
  6. Place three textboxes on the Form.
  7. Select the first textbox, and in the Properties window locate its DataSource property. Set it to Data1.
  8. Set the DataField property of the textbox to Name. The DataField property is a drop-down list with the names of all fields in the student table.
  9. Set the DataSource property of the other textboxes to Data1, and set the DataField property to Roll No, and Class.

Now run the application. The textboxes will display the values of the corresponding fields of the student table. Using the Data control’s buttons, you can move through the records (rows) of the table. Clicking the leftmost button displays the first record of the table, and clicking the button next to it displays the previous record. Clicking the rightmost button displays the last record of the table, and clicking the button next to it displays the next record.