This topic provides code samples of how to work with data tables.
-
Gets the item from the second row and fourth column of the data table
myString = myDatatable.Rows(1)(3).ToString()
-
Deletes the third column in the data table
Columns.RemoveAt(2)
-
Checks if the data table has a column named "Total" and returns true or false
doesContain = myDatatable.Columns.Contains("Total")
-
Gets the index of the column named "Total"
myIndex = myDatatable.Columns.IndexOf("Total")
-
Gets an array of DataRows with all rows where the value of the "Last name" column is equal to "Mayer"
drSelection = dt.Select("Lastname = 'Mayer'")
-
Gets an array of DataRows, sorted in ascending order by the Age column, containing all rows where the value of the LastName column is equal to "Mayer"
drOrderedSelection = dt.Select("Lastname = 'Mayer'", "Age ASC")
-
Combines all values of a given DataRow into a string. The values are separated by " | "
myRowString = String.Join(" | ", row.ItemArray.Select(Function(p) p.ToString()))