'Create a new Datatable...
Dim MyTable = New DataTable("Users")
'************************************************************
'Create The columns in the Datatable...
'************************************************************
Dim column1 As DataColumn = New DataColumn("FirstName")
column1.DataType = System.Type.GetType("System.String")
Dim column2 As DataColumn = New DataColumn("Age")
column2.DataType = System.Type.GetType("System.Int32")
Dim column3 As DataColumn = New DataColumn("ID")
column3.DataType = System.Type.GetType("System.Int32")
Dim column4 As DataColumn = New DataColumn("BirthDate")
column4.DataType = System.Type.GetType("System.DateTime")
'Add the columns to the Datatable...
MyTable.Columns.Add(column1)
MyTable.Columns.Add(column2)
MyTable.Columns.Add(column3)
MyTable.Columns.Add(column4)
'************************************************************
'Create a datarow...
Dim Row1 As DataRow
Row1 = MyTable.NewRow
Row1.Item("FirstName") = "Steve"
Row1.Item("Age") = 44
Row1.Item("ID") = 99
Row1.Item("BirthDate") = #11/24/1963#
'Add the row to the table..
MyTable.Rows.Add(Row1)
Row1 = MyTable.NewRow()
Row1.Item("FirstName") = "Rebee"
Row1.Item("Age") = 41
Row1.Item("ID") = 101
Row1.Item("BirthDate") = #5/11/1967#
'Add the row to the table..
MyTable.Rows.Add(Row1)
'Now let's sort the table and store the result in
'a new table: tmpTable...
MyTable.DefaultView.Sort = "Age asc"
Dim tmpTable As DataTable = MyTable.DefaultView.ToTable
'Show the result of the sort....
MsgBox(tmpTable.Rows(0).Item("FirstName"))
'Delete sample....
'Let's filter the table...
Dim aFoundRows As Array = MyTable.Select("FirstName = 'Steve'")
Dim myRow As DataRow = aFoundRows(0)
MsgBox(myRow.Item("FirstName"))
MyTable.Rows.Remove(aFoundRows(0))
MsgBox(MyTable.Rows.Count)