[.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
.NET Framework 4.5
其他版本
![](http://i3.msdn.microsoft.com/Areas/Epx/Content/Images/ImageSprite.png)
此主题尚未评级 - 评价此主题
表示 DataTable 中的列的架构。
System.Object
System.ComponentModel.MarshalByValueComponent
System.Data.DataColumn
命名空间: System.Data
程序集: System.Data(在 System.Data.dll 中)
C#
C++
F#
VB
DataColumn 类型公开以下成员。
显示: 继承 保护
页首
显示: 继承 保护
页首
显示: 继承 保护
页首
显示: 继承 保护
页首
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
受以下版本支持:4.5.2、4.5.1、4.5、4、3.5、3.0、2.0、1.1、1.0
受以下版本支持: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
DataColumn 类
.NET Framework 4.5其他版本
![](http://i3.msdn.microsoft.com/Areas/Epx/Content/Images/ImageSprite.png)
此主题尚未评级 - 评价此主题
表示 DataTable 中的列的架构。
继承层次结构
System.ObjectSystem.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. Youbuild 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 withseveral 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
相关文章推荐
- [.Net码农].NET Framework 4.5 System.Data 命名空间
- [.Net码农].NET Framework 4.5 DataRow 类
- [.Net码农].NET Framework 4.5 DataTable 类
- [.Net码农]C#动态创建和动态使用程序集、类、方法、字段等(一)
- [.Net码农]将文件上传到数据库 和 从数据库下载文件到本地
- 【.Net码农】C#获取实体类属性名和值 | 遍历类对象
- 在.net 4.5中 操作zip 文件
- 【.Net码农】Server.MapPath()
- 【.Net码农】RDLC报表显示外部图片方法
- .Net 4.5可执行程序OutOfMemory
- 【.Net码农】初试T4模板
- IIS 7.5 .Net 4.5 WCF 404.3错误
- .net 码农转战 iOS - 初探
- 【.Net码农】RDLC(Reportview)报表直接打印,支持所有浏览器,客户可在linux下浏览使用
- 【.Net码农】【MVC】多层架构+MVC+EF+AUTOFAC+AUTOMAPPER
- 【.Net码农】修改WebBrowser控件的内核解决方案
- .NET 4.5性能大跨步:任务并行类库应用(转)
- .NET Framework 4.5打补丁后,VS2012不能打开解决方案
- 基于.NET 4.5 压缩的使用
- .NET 4.5 中新提供的压缩类