What's New
Q & A
Tip Jar
C# Helper...
Follow VBHelper on Twitter
MSDN Visual Basic Community
TitleDisplay the data in a DataSet by using as DataGrid control in VB .NET
DescriptionThis example shows how to display the data in a DataSet by using as DataGrid control in VB .NET.
KeywordsDataSet, DataGrid, VB.NET, data, database, ADO.NET
CategoriesDatabase, VB.NET, Controls
First, create a DataSet for the database. Also create a DataAdapter for each table that you want to load into the DataSet.

  1. Create the form and add two OleDbDataAdapters. Configure them to select the Students and Scores tables from the database. (Note that you will probably need to reconfigure the example program's adapters to find the new database location.)
  2. Select the adapters and select the Data menu's Generate DataSet command. Give the DataSet a meaningful type such as TestScoresDataSet, verify that both of the DataAdapters are checks, and click OK.
  3. Rename the instance of the DataSet that was placed on the form. For example, call it dsTestScores.

Next add a DataGrid to the program's form. Set its DataSource property to the DataSet.

Alternatively, you can set the DataSource to one of the DataSet's tables. If you do that, the DataGrid will only display records in that table. If you set DataSource to the whole DataSet, the DataGrid will let the user explore all of the tables.

When the program starts, it uses the following code to load the data into the DataSet.

That's all there is to it! The DataGrid provides all of the navigation through the DataSet automatically.

' Load the DataSet.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
End Sub
For more information on database programming in VB .NET, see my book Visual Basic .NET Database Programming.
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.