DekGenius.com
[ Team LiB ] Previous Section Next Section

DataColumn diposable

System.Data (system.data.dll) class

The DataColumn represents a column schema within a table. The DataTable stores the DataColumn objects in its DataTable.Columns collection. The DataColumn object doesn't contain data. Instead, it defines the properties of a column such as the .NET data type (DataType ), whether it allows null values (AllowDBNull ), whether it is read-only (ReadOnly ), whether values in each row of the column must be unique (Unique ), the column name (ColumnName ), the default value when a new row is created (DefaultValue ), the maximum length for text fields (MaxLength ), and the position relative to other columns in the table (Ordinal ). If you retrieve data without schema information, some of these values (such as MaxLength ) aren't initialized. However, even if you do retrieve schema information, you'll find that some information, such as DefaultValue , is never retrieved from the data source.

The DataColumn class provides additional properties, such as ExtendedProperties , which is a collection you can use to store miscellaneous information, and ColumnMapping , which allows you to configure the XML representation for each column in a DataTable using a value from the MappingType enumeration. Finally, the Expression property allows you to define a calculated or aggregate column or one that is stored as an expression or calculation. For example, you use a statement such as:

dt.Columns("Total").Expression = "Price * 1.15"; 

to define an expression for a column that shows the tax-adjusted value from the Price column. It assumes you've created and added the Total column. For a complete example, as well as information about the syntax used for expression functions, operators, and table relations, refer to Chapter 8.

public class DataColumn : System.ComponentModel.MarshalByValueComponent {
// Public Constructors
   public DataColumn(  );  
   public DataColumn( string columnName);  
   public DataColumn( string columnName, Type dataType);  
   public DataColumn(string columnName, Type dataType, string expr);
   public DataColumn(string columnName, Type dataType, string expr, MappingType type);
// Public Instance Properties
   public bool AllowDBNull{set; get; } 
   public bool AutoIncrement{set; get; } 
   public long AutoIncrementSeed{set; get; } 
   public long AutoIncrementStep{set; get; } 
   public string Caption{set; get; } 
   public virtual MappingType ColumnMapping{set; get; } 
   public string ColumnName{set; get; } 
   public Type DataType{set; get; } 
   public object DefaultValue{set; get; } 
   public string Expression{set; get; } 
   public PropertyCollection ExtendedProperties{get; } 
   public int MaxLength{set; get; } 
   public string Namespace{set; get; } 
   public int Ordinal{get; } 
   public string Prefix{set; get; } 
   public bool ReadOnly{set; get; } 
   public DataTable Table{get; } 
   public bool Unique{set; get; } 
// Public Instance Methods
   public override string ToString(  );                // overrides System.ComponentModel.MarshalByValueComponent
// Protected Instance Methods
   protected internal void CheckNotAllowNull(  );  
   protected void CheckUnique(  );  
   protected internal virtual void OnPropertyChanging(System.ComponentModel.PropertyChangedEventArgs pcevent);
   protected internal void RaisePropertyChanging(string name);
}

Hierarchy

System.Object figs/U2192.gif System.ComponentModel.MarshalByValueComponent(System.ComponentModel.IComponent, System.IDisposable , System.IServiceProvider) figs/U2192.gif DataColumn

Returned By

System.Data.Common.DataColumnMapping.GetDataColumnBySchemaAction( ) , DataColumnChangeEventArgs.Column , DataColumnCollection.{Add( ) , this} , DataRelation.{ChildColumns , ParentColumns} , DataRow.GetColumnsInError( ) , DataTable.PrimaryKey , ForeignKeyConstraint.{Columns , RelatedColumns} , UniqueConstraint.Columns

Passed To

Multiple types

    [ Team LiB ] Previous Section Next Section