DataTable Class
Namespace
System.Data
Syntax
public sealed class DataTable : MarshalByValueObject, IListSource, IBindingList
Namespace: System.Data
Assembly: System.Data.dll
Description
Represents an in-memory collection of tables that provides a relational data structure. DataTable is one of the primary classes used to represent data in ADO.NET.
A DataTable can be used on its own to represent a single table of data, or it can be used with a DataSet to represent the tables in a relational database.
Key features of DataTable include:
- Columns: Defines the schema of the table, including data types and constraints.
- Rows: Stores the actual data for the table.
- Constraints: Enforces data integrity through primary keys, unique constraints, and foreign keys.
- Relations: Defines relationships between
DataTableobjects within aDataSet. - DataView: Allows for sorting, filtering, and searching of the data in the
DataTable.
Properties
| Name | Description | Access |
|---|---|---|
| CaseSensitive | Gets or sets a value indicating whether string comparisons within this table are case-sensitive. | Read/Write |
| ChildRelations | Gets a collection of DataRelation objects that represent the child relations for this DataTable. |
Read |
| Columns | Gets a DataColumnCollection that contains the columns for this DataTable. |
Read |
| Constraints | Gets a ConstraintCollection that contains all constraints for this DataTable. |
Read |
| DataSet | Gets the DataSet that contains this DataTable. |
Read |
| DefaultView | Gets a DataView object that can be used to navigate and manipulate the data in the DataTable. |
Read |
| DisplayExpression | Gets or sets the expression used to create a display string that identifies this table. | Read/Write |
| HasErrors | Gets a value indicating whether there are errors in any rows in this table. | Read |
| IsInitialized | Gets a value indicating whether the DataTable has been initialized. |
Read |
| Locale | Gets or sets information about the current culture for this DataTable. |
Read/Write |
| MinimumCapacity | Gets or sets the initial capacity of the DataTable. |
Read/Write |
| ParentRelations | Gets a collection of DataRelation objects that represent the parent relations for this DataTable. |
Read |
| PrimaryKey | Gets or sets the array of columns that constitute the primary key for this DataTable. |
Read/Write |
| RemotingContext | Gets or sets the context that is used for remoting. | Read/Write |
| Rows | Gets a DataRowCollection that contains the rows for this DataTable. |
Read |
| Site | Gets or sets the site of the component. | Read/Write |
| TableName | Gets or sets the name of this DataTable. |
Read/Write |
Methods
| Name | Description |
|---|---|
|
AcceptChanges()
Commits all changes that have been made to this public void AcceptChanges(); |
Commits all changes made to this DataTable. |
|
BeginInit()
Begins a bulk update of the public void BeginInit(); |
Begins a bulk update. |
|
Clear()
Removes all rows and columns from the public void Clear(); |
Clears all rows and columns. |
|
Clone()
Creates a new public DataTable Clone(); |
Creates a copy of the schema. |
|
Compute(string expression, string filter)
Evaluates the given expression by using Parameters: public object Compute(string expression, string filter); |
Evaluates an expression. |
|
Copy()
Creates a new public DataTable Copy(); |
Creates a copy of the table and its data. |
|
CreateInstance()
Creates a protected virtual object CreateInstance(); |
Creates an instance of the table. |
|
Dispose()
Releases the unmanaged resources that are used by the current instance of the public void Dispose(); |
Releases resources. |
|
EndInit()
Ends the bulk update of the public void EndInit(); |
Ends a bulk update. |
|
Equals(object obj)
Determines whether the specified object is equal to the current object. Parameters: public override bool Equals(object obj); |
Determines if two objects are equal. |
|
Find(object primaryKey, ...)
Finds the row that has the specified primary key value. Assumes that the primary key has already been set. Parameters: public DataRow Find(object primaryKey); |
Finds a row by its primary key. |
|
GetChanges()
Returns a copy of the public DataTable GetChanges(); |
Returns a copy of the table with changes. |
|
GetErrors()
Returns a public DataRow[] GetErrors(); |
Returns rows with errors. |
|
GetHashCode()
Serves as the default hash function. public override int GetHashCode(); |
Serves as the default hash function. |
|
GetType()
Gets the Type of the current instance. public override Type GetType(); |
Gets the type of the current instance. |
|
ImportRow(DataRow row)
Imports a Parameters: public void ImportRow(DataRow row); |
Imports a data row. |
|
Load(IDataReader reader, LoadOption loadOption, params DataTable[] tables)
Loads data from an Parameters: public void Load(IDataReader reader, LoadOption loadOption, params DataTable[] tables); |
Loads data from an IDataReader. |
|
Merge(DataTable table)
Merges the current Parameters: public void Merge(DataTable table); |
Merges with another DataTable. |
|
NewRow()
Creates a new public DataRow NewRow(); |
Creates a new DataRow. |
|
OnRowChanged(DataRowChangeEventArgs e)
Raises the Parameters: protected virtual void OnRowChanged(DataRowChangeEventArgs e); |
Raises the RowChanged event. |
|
OnRowChanging(DataRowChangeEventArgs e)
Raises the Parameters: protected virtual void OnRowChanging(DataRowChangeEventArgs e); |
Raises the RowChanging event. |
|
OnRowDeleted(DataRowChangeEventArgs e)
Raises the Parameters: protected virtual void OnRowDeleted(DataRowChangeEventArgs e); |
Raises the RowDeleted event. |
|
OnRowDeleting(DataRowChangeEventArgs e)
Raises the Parameters: protected virtual void OnRowDeleting(DataRowChangeEventArgs e); |
Raises the RowDeleting event. |
|
ReadXml(string fileName)
Reads XML data into the Parameters: public void ReadXml(string fileName); |
Reads XML data from a file. |
|
RejectChanges()
Rejects all changes that have been made to this public void RejectChanges(); |
Rejects all changes. |
|
Reset()
Resets the public void Reset(); |
Resets the DataTable. |
|
Select(string filterExpression)
Returns an array of Parameters: public DataRow[] Select(string filterExpression); |
Selects rows based on a filter expression. |
|
ToString()
Returns a string that represents the current object. public override string ToString(); |
Returns a string representation. |
|
WriteXml(string fileName)
Writes the Parameters: public void WriteXml(string fileName); |
Writes XML data to a file. |