What is a DataTable?

You are currently viewing What is a DataTable?

Overview

A DataTable represents one table (collection of rows and columns) of data. For example, an excel spreadsheet of data would be considered a DataTable. Below is an example of a simple DataTable:

Fruit Color Price
Apple
Red
$0.99
Pear
Green
$0.75
Blueberries
Blue
$1.20

DataTables are very useful for automation as they can assist with manipulating and modifying large sets of data just as you would with an excel spreadsheet.

Below are the key characteristics of a DataTable:

  • Variable Size – The size of a DataTable is not fixed and new rows or columns can be added at any point during an automation.
  • Ordered Rows & Columns – The columns and rows of a DataTable are in a specific order which can be changed using various methods.
  • Various Data Type – DataTables can house various data types as long as all values within one column are the same data type. That means you can have one column storing integers and another storing strings in the same DataTable.

What can you do with DataTables?

Below are some great examples of the use of DataTables:

  • Add Data Row/Column
  • Filter Data Table
  • Join Data Table
  • Remove Duplicate Rows
  • Remove Data Rows/Columns

Commonly Used Properties

The following are some commonly used properties DataTables. A property is a characteristic or attribute of an object (i.e. DataTable). To learn more about properties, click here

Columns - Obtains a collection of columns.

Example Property Return Type
DataTable.Columns
DataColumnCollection

Rows - Obtains a collection of rows.

Example Property Return Type
DataTable.Rows
DataRowCollection

Commonly Used Methods

The following are some commonly used methods for DataTables. Methods are actions that objects (i.e. DataTables) can perform. To learn more about methods, click here.

Select - Gets an array of DataRow objects.

Example Method Return Type
DataTable.Select
DataRow[]

Select(String) - Gets an array of filtered DataRow objects.

Example Method Return Type
DataTable.Select("[Name]='George'")
DataRow[]

Clear - Clears the DataTable of all data.

Example Method Return Type
DataTable.Clear
DataTable

Clone - Clones the structure of the DataTable, but does not clone the data within.

Example Method Return Type
DataTable.Clone
DataTable

Copy - Copies both the structure and data of the DataTable.

Example Method Return Type
DataTable.Copy
DataTable