How to Build a Data Set From VB Code

A Visual Basic "DataSet" control contains data tables from a database, a file or your own data creation. You must first create a "DataTable" object with defined fields and populate the table with your data. After you create the table and fill it with data, you use the table to create a DataSet. The DataSet object lets you fill other .NET controls such as a grid, so you can display the data to your readers.

Instructions

    • 1

      Click the Windows "Start" button and select "All Programs." Click "Microsoft .NET," then click "Visual Studio." Open your VB project in the software to load all the coding files.

    • 2

      Double-click the code file you want to use to set up the DataSet. Start the code with the creation of a DataTable. The following code creates a DataTable named "table" and creates two columns for the table:

      Dim table As DataTable
      table = New DataTable()
      fnameColumn = New DataColumn("fname", Type.GetType("System.String"))
      lnameColumn = New DataColumn("lname", Type.GetType("System.String"))
      table.Columns.Add(fnameColumn)
      table.Columns.Add(lnameColumn )

    • 3

      Add some data to the table. The following code adds two customers to the DataTable object:

      row = table.NewRow()
      row("fname") = "Joe"
      row("lname") = "Smit"
      row.Rows.Add(row)

      row= table.NewRow()
      row("fname") = "Jane"
      row("lname") = "Smith"
      table.Rows.Add(row)

    • 4

      Fill a DataSet object with the table data. The following code creates a DataSet object and fills the DataSet with the table data from previous steps:

      Dim data as New DataSet()
      data.Tables.Add(table)

Related Searches:

References

Comments

Related Ads

Featured