How to Add a DataRow to a DataTable

A "DataTable" is a Visual Basic programming object that lets you create record sets. A DataTable is similar to a database table. It has rows and columns, and each field contains your information. DataTables are a convenient way to hold large sets of data in your Windows code. To add a "DataRow," you call the "Add" function on your DataTable.

Instructions

    • 1

      Click the Windows "Start" button and click "All Programs" in the menu. Click ".NET Programming," then click the "Visual Studio" shortcut to load the software.

    • 2

      Click "File" in the main Visual Studio window. Click "Open." A list of Visual Basic projects is shown. Click the project you want to edit and select "Open." The code file opens on your desktop.

    • 3

      Create the DataTable. In this example, a DataTable that contains records of customers is created. Type the following code in your project:

      Dim table As DataTable

      Dim row As DataRow

    • 4

      Assign the information to the DataRow. You must populate the DataRow with information before you add it to the table. Type the following code into the file:

      row("firstname") = "Joe"

      row("lastname") = "Smith"

    • 5

      Add the row to the DataTable. The following code adds the row to the table:

      table.Tables(0).Rows.Add(row)

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured