Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

454 Part IV Database and Web Programming


Use the Data Sources window to create database objects on a form


  1. In the Data Sources window, click the arrow next to the Faculty node to display the
    available fields in Faculty2010DataSet (if you have not already done so).
    Your Data Sources window looks like the previous screen shot. In Visual Studio 2010,
    you can display individual fields or an entire table of data by simply dragging the
    desired database objects onto your form.

  2. Click the Last Name field, which contains the name of each instructor in the Faculty2010
    database. An arrow appears to the right of the Last Name field in the Data Sources
    window. If the arrow does not appear, make sure that the Form1 .vb [Design] tab is
    active in the Designer window, and then click Last Name again.

  3. Click the Last Name arrow.


Clicking this arrow displays a list of options related to how a database field is displayed
on the form when you drag it, as shown in the following screen shot:

Although I haven’t discussed it yet, most of the controls on the Common Controls tab
of the Toolbox have the built-in ability to display database information. In Visual Studio
terminology, these controls are called bound controls when they are connected to
data-ready fields in a dataset. The list of controls you see now is a group of popular
options for displaying string information from a database, but you can add additional
controls to the list (or remove items) by clicking the Customize command. In this case,
however, you’ll simply use the TextBox control, the default bound control for string data.


  1. Click TextBox in the list, and then drag the Last Name field to the middle of the form in
    the Windows Forms Designer.
    As you drag the field over the form, a plus sign (+) below the pointer indicates
    that adding this database object to a form is a valid operation. When you release
    the mouse button, Visual Studio creates a data-ready text box object and places

Free download pdf