How to Use a DataTable in VB.NET

Written by jim campbell
  • Share
  • Tweet
  • Share
  • Email

The VB.NET "DataTable" control contains rows and columns of data you use to insert data in a DataGrid. A DataGrid displays the DataTable information in a formatted display. You must first create the DataTable columns, insert the data, then bind the DataTable to the DataGrid. A DataTable control can also contain multiple tables, so you can set up multiple DataGrids at once.

Skill level:


  1. 1

    Right-click the "SLN" file, which is the main Visual Studio file that contains all your website code. Click "Open With," then double-click "Visual Studio."

  2. 2

    Double-click the code file that contains the DataGrid you need to set up. Start the code with a DataTable variable:

    Dim table As DataTable = new DataTable("MyTable")

  3. 3

    Set up the DataTable columns:

    column = New DataColumn()

    column.ColumnName = "first name"


    column = New DataColumn()

    column.ColumnName = "last name"


    You must create a column object for each field in the table, assign it a name and add the column to the DataTable.

  4. 4

    Add the data to the table:

    row = table.NewRow()

       row("first name") = "Joe"

    row("last name") = "Smith"

  5. 5

    Add the table to a data set object -- the data set lets you transfer the table to the DataGrid:

    ds = New DataSet()

  6. 6

    Fill the DataGrid with the DataTable information and bind the table to the DataGrid:


Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.