您的位置:首页 > 职场人生

[.Net码农].NET Framework 4.5 DataColumn 类

2014-10-27 09:56 253 查看
http://msdn.microsoft.com/zh-cn/library/system.data.datacolumn(v=vs.80).aspx


DataColumn 类

.NET Framework 4.5

其他版本



此主题尚未评级 - 评价此主题

表示 DataTable 中的列的架构。



继承层次结构

System.Object

System.ComponentModel.MarshalByValueComponent

System.Data.DataColumn

命名空间: System.Data

程序集: System.Data(在 System.Data.dll 中)



语法

C#

C++

F#

VB

public class DataColumn : MarshalByValueComponent


DataColumn 类型公开以下成员。



构造函数

显示: 继承 保护

名称说明



DataColumn()将 DataColumn 类的新实例初始化为类型字符串。



DataColumn(String)使用指定的列名称将 DataColumn 类的新实例初始化为类型字符串。



DataColumn(String, Type)使用指定列名称和数据类型初始化 DataColumn 类的新实例。



DataColumn(String, Type, String)使用指定的名称、数据类型和表达式初始化 DataColumn 类的新实例。



DataColumn(String, Type, String, MappingType)使用指定名称、数据类型、表达式和确定列是否为特性的值,初始化 DataColumn 类的新实例。
页首



属性

显示: 继承 保护

名称说明



AllowDBNull获取或设置一个值,该值指示对于属于该表的行,此列中是否允许空值。



AutoIncrement获取或设置一个值,该值指示对于添加到该表中的新行,列是否将列的值自动递增。



AutoIncrementSeed获取或设置其 AutoIncrement 属性设置为 true 的列的起始值。 默认值为
0。



AutoIncrementStep获取或设置其 AutoIncrement 属性设置为 true 的列使用的增量。



Caption获取或设置列的标题。



ColumnMapping获取或设置列的 MappingType



ColumnName获取或设置 DataColumnCollection 中的列的名称。



Container获取组件的容器。 (继承自 MarshalByValueComponent。)



DataType获取或设置存储在列中的数据的类型。



DateTimeMode获取或设置列的 DateTimeMode。



DefaultValue在创建新行时获取或设置列的默认值。



DesignMode获取指示组件当前是否处于设计模式的值。 (继承自 MarshalByValueComponent。)



Events获取附加到该组件的事件处理程序的列表。 (继承自 MarshalByValueComponent。)



Expression获取或设置表达式,用于筛选行、计算列中的值或创建聚合列。



ExtendedProperties获取与 DataColumn 相关的自定义用户信息的集合。



MaxLength获取或设置文本列的最大长度。



Namespace获取或设置 DataColumn 的命名空间。



Ordinal获取列在 DataColumnCollection 集合中的位置(从零开始)。



Prefix获取或设置一个 XML 前缀,该前缀是 DataTable 的命名空间的别名。



ReadOnly获取或设置一个值,该值指示一旦向表中添加了行,列是否还允许更改。



Site获取或设置组件的位置。 (继承自 MarshalByValueComponent。)



Table获取列所属的 DataTable



Unique获取或设置一个值,该值指示列的每一行中的值是否必须是唯一的。
页首



方法

显示: 继承 保护

名称说明



CheckNotAllowNull基础结构。该成员支持 .NET Framework 结构,不应从代码直接使用。



CheckUnique基础结构。该成员支持 .NET Framework 结构,不应从代码直接使用。



Dispose()释放由 MarshalByValueComponent 使用的所有资源。 (继承自 MarshalByValueComponent。)



Dispose(Boolean)释放由 MarshalByValueComponent 占用的非托管资源,还可以另外再释放托管资源。 (继承自 MarshalByValueComponent。)



Equals(Object)确定指定的对象是否等于当前对象。 (继承自 Object。)



Finalize允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 MarshalByValueComponent。)



GetHashCode作为默认哈希函数。 (继承自 Object。)



GetService获取 IServiceProvider 的实施者。 (继承自 MarshalByValueComponent。)



GetType获取当前实例的 Type。 (继承自 Object。)



MemberwiseClone创建当前 Object 的浅表副本。 (继承自 Object。)



OnPropertyChanging该成员支持 .NET Framework 结构,不应从代码直接使用。



RaisePropertyChanging该成员支持 .NET Framework 结构,不应从代码直接使用。



SetOrdinal将 DataColumn 的序号或位置更改为指定的序号或位置。



ToString获取列的 Expression(如果存在的话)。 (重写 MarshalByValueComponent.ToString()。)
页首



事件

显示: 继承 保护

名称说明



Disposed添加事件处理程序以侦听组件上的 Disposed 事件。 (继承自 MarshalByValueComponent。)
页首



备注

The DataColumn is the fundamental building block for creating the schema of a DataTable. You
build the schema by adding one or more DataColumn objects to theDataColumnCollection. For
more information, see 向数据表中添加列.

Each DataColumn has a DataType property
that determines the kind of data the DataColumn contains. For example, you can restrict the data type to integers, or strings, or decimals. Because
data that is contained by the DataTable is typically merged back into
its original data source, you must match the data types to those in the data source. For more information, see ADO.NET
中的数据类型映射.

Properties such as AllowDBNull, Unique,
and ReadOnly put restrictions on the entry and updating of
data, thereby helping to guarantee data integrity. You can also use theAutoIncrement, AutoIncrementSeed,
and AutoIncrementStep properties to control automatic
data generation. For more information about AutoIncrement columns,
see 创建 AutoIncrement 列. For more information,
see 定义主键.

You can also make sure that values in a DataColumn are unique by creating a UniqueConstraint and
adding it to the ConstraintCollection of the DataTable to
which theDataColumn belongs. For more information, see 数据表约束.

To create a relation between DataColumn objects, create a DataRelation object
and add it to the DataRelationCollection of a DataSet.

You can use the Expression property
of the DataColumn object to calculate the values in a column, or create an aggregate column. For more information, see 创建表达式列.



示例

The following example creates a DataTable with
several DataColumn objects.

C#

VB

private void MakeTable()
{
// Create a DataTable.
DataTable table = new DataTable("Product");

// Create a DataColumn and set various properties.
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Decimal");
column.AllowDBNull = false;
column.Caption = "Price";
column.ColumnName = "Price";
column.DefaultValue = 25;

// Add the column to the table.
table.Columns.Add(column);

// Add 10 rows and set values.
DataRow row;
for(int i = 0; i < 10; i++)
{
row = table.NewRow();
row["Price"] = i + 1;

// Be sure to add the new row to the
// DataRowCollection.
table.Rows.Add(row);
}
}




版本信息


.NET Framework

受以下版本支持:4.5.2、4.5.1、4.5、4、3.5、3.0、2.0、1.1、1.0


.NET Framework Client Profile

受以下版本支持:4、3.5 SP1



平台

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008(不支持服务器核心角色), Windows Server 2008 R2(支持带 SP1 或更高版本的服务器核心角色;不支持 Itanium)

.NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参阅.NET Framework 系统要求



线程安全

This type is safe for multithreaded read operations. You must synchronize any write operations.



请参阅


参考

System.Data 命名空间
Add
DataColumnCollection
Constraints
ConstraintCollection
System.Windows.Forms.DataGrid
DataRow
DataTable
DataSet
NewRow
DataRowCollection
UniqueConstraint


其他资源

DataSet、DataTable 和 DataView
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: