Visual Basic: Programmatically create a datatable

Platform:Visual Basic
Task:Programmatically create a datatable
Discussion:
Programmatically create a datatable
Example:
    Private Sub CreateDataTable()
        dgData.Columns.Clear()
        Dim GPSTable As New DataTable

        Dim CollarIDColumn As DataColumn
        CollarIDColumn = New DataColumn()
        CollarIDColumn.DataType = System.Type.GetType("System.Int32")
        CollarIDColumn.ColumnName = "CollarID"

        GPSTable.Columns.Add(CollarIDColumn)


        'rows
        Dim mRow As DataRow
        mRow = GPSTable.NewRow
        mRow.Item(0) = -123456
        GPSTable.Rows.Add(mRow)

        mRow = GPSTable.NewRow
        mRow.Item(0) = 9876
        GPSTable.Rows.Add(mRow)
    End Sub
Back to Index