''DataTable'' ''serializable, disposable'

DataTable serializable, disposable

System.Data (system.data.dll) class

The DataTable object contains the schema and data for a single table. Column settings, such as column names and data types are specified using the DataColumn objects contained in the table and accessed using the Columns property. Each row of data is encapsulated within a separate DataRow object, which is accessed using the Rows property. Also, ForeignKeyConstraint and UniqueConstraint objects can be added to the ConstraintCollection for the table, which is accessed using the Constraints property.

The DataTable provides many of the same methods as the DataSet . For example, you can use Copy( ) , Clone( ) , Clear( ) , GetChanges( ) , HasErrors , and AcceptChanges( ) in the same way as described for the DataSet . In addition, you can use the Select( ) method to retrieve an array of DataRow objects that match a specified SQL filter expression. There are four overloaded versions of the Select( ) method, some of which allow you to specify a sort order and filter based on the DataRowState of the DataRow . Finally, you can use the NewRow( ) method to generate a new DataRow object that has the same schema as the DataTable . This is detached row; once you have finished entering the required information you must add it to the RowCollection .

The DataTable has six events that allow you to react when column values are changed. You can handle RowChanging to implement row-specific validation rules or handle ColumnChanging to implement column-specific validation rules. Both events fire during the course of a column edit; the difference is that ColumnChanging provides a reference to a DataColumn object. RowChanged , ColumnChanged , and RowDeleted occur after a change has been applied. They are most useful if you need to log the change or update part of the user interface.

public class DataTable : System.ComponentModel.MarshalByValueComponent , 
System.ComponentModel.IListSource, System.ComponentModel.ISupportInitialize, 
System.Runtime.Serialization.ISerializable {
// Public Constructors
   public DataTable(  );  
   public DataTable( string tableName);  
// Protected Constructors
   protected DataTable(
        System.Runtime.Serialization.SerializationInfo info, 
        System.Runtime.Serialization.StreamingContext context);  
// Public Instance Properties
   public bool CaseSensitive{set; get; } 
   public DataRelationCollection ChildRelations{get; } 
   public DataColumnCollection Columns{get; } 
   public ConstraintCollection Constraints{get; } 
   public DataSet DataSet{get; } 
   public DataView DefaultView{get; } 
   public string DisplayExpression{set; get; } 
   public PropertyCollection ExtendedProperties{get; } 
   public bool HasErrors{get; } 
   public CultureInfo Locale{set; get; } 
   public int MinimumCapacity{set; get; } 
   public string Namespace{set; get; } 
   public DataRelationCollection ParentRelations{get; } 
   public string Prefix{set; get; } 
   public DataColumn[ ] PrimaryKey{set; get; } 
   public DataRowCollection Rows{get; } 
   public override ISite Site{set; get; }                 // overrides System.ComponentModel.MarshalByValueComponent
   public string TableName{set; get; } 
// Public Instance Methods
   public void AcceptChanges(  );  
   public void BeginInit(  );                               // implements System.ComponentModel.ISupportInitialize
   public void BeginLoadData(  );  
   public void Clear(  );  
   public virtual DataTable Clone(  );  
   public object Compute( string expression, string filter);  
   public DataTable Copy(  );  
   public void EndInit(  );                                 // implements System.ComponentModel.ISupportInitialize
   public void EndLoadData(  );  
   public DataTable GetChanges(  );  
   public DataTable GetChanges( DataRowState rowStates);  
   public DataRow[ ] GetErrors(  );  
   public void ImportRow( DataRow row);  
   public DataRow LoadDataRow(object[ ] values, bool fAcceptChanges);
   public DataRow NewRow(  );  
   public void RejectChanges(  );  
   public virtual void Reset(  );  
   public DataRow[ ] Select(  );  
   public DataRow[ ] Select( string filterExpression);  
   public DataRow[ ] Select(string filterExpression, string sort); 
   public DataRow[ ] Select(string filterExpression, string sort, DataViewRowState recordStates);
   public override string ToString(  );                // overrides System.ComponentModel.MarshalByValueComponent
// Protected Instance Methods
   protected virtual DataTable CreateInstance(  );  
   protected virtual Type GetRowType(  );  
   protected internal DataRow[ ] NewRowArray( int size);  
   protected virtual DataRow NewRowFromBuilder(DataRowBuilder builder);
   protected virtual void OnColumnChanged(
        DataColumnChangeEventArgs e);  
   protected virtual void OnColumnChanging(DataColumnChangeEventArgs e);
   protected internal virtual void OnPropertyChanging(System.ComponentModel.PropertyChangedEventArgs pcevent);
   protected internal virtual void OnRemoveColumn(DataColumn column);
   protected virtual void OnRowChanged(DataRowChangeEventArgs e);
   protected virtual void OnRowChanging(DataRowChangeEventArgs e);
   protected virtual void OnRowDeleted(DataRowChangeEventArgs e);
   protected virtual void OnRowDeleting(DataRowChangeEventArgs e);
// Events
   public event DataColumnChangeEventHandler ColumnChanged;  
   public event DataColumnChangeEventHandler ColumnChanging;  
   public event DataRowChangeEventHandler RowChanged;  
   public event DataRowChangeEventHandler RowChanging;  
   public event DataRowChangeEventHandler RowDeleted;  
   public event DataRowChangeEventHandler RowDeleting;  


System.Object figs/U2192.gif System.ComponentModel.MarshalByValueComponent(System.ComponentModel.IComponent, System.IDisposable , System.IServiceProvider) figs/U2192.gif DataTable(System.ComponentModel.IListSource, System.ComponentModel.ISupportInitialize , System.Runtime.Serialization.ISerializable)

Returned By

Multiple types

Passed To

Multiple types

    Part I: ADO.NET Tutorial
    Part II: ADO.NET Core Classes
    Part III: API Quick Reference
    Chapter 34. The System.Data Namespace