Showing Information to the User: Displaying Data in Your User Interface

In this lesson, you will learn how to create a basic user interface for viewing the data in a local database.

Now that you have created a connection to a local database file, the next step is to create a user interface to display the data. The programming behind retrieving data from a database and displaying it in a user interface is very complex. Fortunately, Visual Basic automatically creates and configures the required data objects for you, so that all you have to do is select and position the objects. In this lesson, you will learn how to create a simple data display form.

Try It!

To create a data access form

  1. Open the Addresses project from the previous lesson. If you have not yet completed it, go to Getting the Information You Need: Connecting to an Existing Database and finish that lesson before you continue.

  2. In Solution Explorer, select Form1.vb, and then on the View menu, click Designer.

  3. In Solution Explorer, click the Data Sources tab.

    In the Data Sources window, take some time to explore the FirstDatabaseDataSet and Addresses nodes. You can expand the Addresses node to view all the individual fields in the table.

  4. Drag the Addresses node from the Data Sources window to the form.

    Note

    Some controls are automatically added to the form, and several components are created and added to the component tray underneath the form. There is a DataGridView control that will display the rows and columns of the table, and a control for navigation (the AddressesBindingNavigator). Additionally, Visual Basic creates components that connect to the database, manage retrieval and updating of data, and store the data in a local DataSet (AddressesBindingSource, AddressesTableAdapter, and FirstDatabaseDataSet, respectively).

  5. Select the AddressesDataGridView control, and in the Properties window, set the Dock property to Fill (click the center button).

    This will expand the grid to fill the form.

  6. Press F5 to run your program.

    The data from the Addresses table is displayed in the DataGridView control on the form. You can use the controls in the BindingNavigator at the top of the form to navigate between rows, and even add or delete records. You can also change the records by modifying the data displayed in the grid, but these changes will not be saved unless you click the Save Data icon. You will learn how to automatically save changes to your data in the next topic.

Next Steps

In this lesson, you learned how to use the Visual Basic visual tools to create a basic data-oriented user interface. In the next lesson, you will learn how to create a data entry form and save changes to the database.

Next Lesson: Adding or Modifying Your Records: Updating Data

See Also

Tasks

Getting the Information You Need: Connecting to an Existing Database

Other Resources

Managing Your Records: Using Data in Your Program

Visual Basic Guided Tour

SQL Server Compact 3.5 Books Online