In this article, you will learn how to create an ADO.NET DataTable at run-time and use its properties and methods using C#.
This chapter has been excerpted from book "A Programmer's Guide to ADO.NET in C#".In the previous articles you've already seen that columns and rows are the building block of a data table. You need to work with the DataColumn and DataRow objects to create data tables and add data to them. Besides creating a data table schema and adding rows to it, a data table has more to offer. The DataTable object represents a data table. Before creating a data table, I'll show you the DataTable class properties and methods. Table 1 describes some of the common DataTable properties, and Table 2 summarizes some of the common DataTable methods.Table 1: The Data Table class properties
PROPERTY
DESCRIPTION
Columns
Represents all table columns
Constraints
Represents all table constraints
DataSet
Returns the dataset for the table
DefaultView
Customized view of the data table
ChildRelation
Return child relations for the data table
ParentRelation
Returns parent relations for the data table
PrimaryKey
Represents an array of columns that function as primary key for the table
Rows
All rows of the data table
TableName
Name of the table
METHOD
AcceptChanges
Commits all the changes made since last AcceptChanges was called
Clear
Deletes all data table data
Clone
Creates a clone of a DataTable including its schema
Copy
Copies a data table including its schema
NewRow
Creates a new row, which is later added by calling the Rows.Add method
RejectChanges
Reject all changed made after last AcceptChanges was called
Reset
Resets a data table's original state
Select
Gets an array of rows based on the criteria
Pro WPF: Windows Presentation Foundation in .NET 3.0