C# DataColumn
来源:互联网 发布:搞笑网络剧排行榜 编辑:程序博客网 时间:2024/05/18 20:11
DataColumn designates columns in DataTables. It specifies the name and type of certain columns in the table. The DataColumn type can be instantiated through the Columns.Add method or through the DataColumn constructor itself. The Columns collection can be looped through.
Example
You can construct a DataTable using DataColumn references and the DataColumn constructor. The example also adds some rows to the DataTable based on the types and count of the columns specified by the DataColumn references.
Additionally:The program uses a foreach-loop on the Columns property to print out the names and types of the columns on the DataTable.
Program that uses DataColumn [C#]using System;using System.Data;class Program{ static void Main() {//// Construct the DataTable.//DataTable table = GetTable();//// Loop over the column headers in the DataTable.//foreach (DataColumn column in table.Columns){ Console.WriteLine("{0} = {1}", column, column.DataType);} } /// <summary> /// Generates a DataTable with four columns. /// </summary> static DataTable GetTable() {//// Here we create a DataTable and add columns to it.//DataTable table = new DataTable();table.Columns.Add("Dosage", typeof(int));table.Columns.Add("Medication", typeof(string));table.Columns.Add("Patient", typeof(string));//// Add another column to the data table in a different way.//DataColumn column = new DataColumn("Appointment", typeof(DateTime));table.Columns.Add(column);//// Here we add some DataRows.// Note that the row parameters must match the order and types of the columns.//table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);return table; }}OutputDosage = System.Int32Medication = System.StringPatient = System.StringAppointment = System.DateTime
Adding columns to DataTable. The program text shows that you can add DataColumn instances with the Add method on the Columns instance property on the DataTable instance. Internally, this overload of the Add method actually just constructs a new DataColumn in the same way as shown next.
However:This method signature hides some of the complexity from you, which can help simplify certain programs.
DataColumn constructor. The program text demonstrates the "new DataColumn" constructor which receives two parameters. There are other overloaded DataColumn constructors, but you can use the same general pattern when constructing them.
Tip:You can pass an actual DataColumn instance reference to the Add method on the Columns collection.
Foreach loop. The Main method uses a foreach-loop after constructing the DataTable. It accesses the Columns instance property on the DataTable instance and loops over this with a DataColumn iteration variable. The iteration variable is always read-only, but you can access writable data through the reference itself. The loop prints out each column name and then the data type the column stores.
Internals
Individual DataColumn references can be accessed by specified by their string names in the indexer on the DataColumnCollection. Internally, these DataColumn references are stored in a Hashtable, and the indexer just uses the Hashtable to look up the references themselves.
Indexer ExamplesHashtable ExamplesAbstractions
The DataTable, DataColumn, and DataRow classes serve as in-memory relational database representations in the .NET Framework. The entire point of relational databases such as SQL Server is to store data in a structured way, but there is a conflict when translating tabular data to in-memory object models and representations.
The DataColumn type is one way you can represent the data in memory without using the database constantly. You can find more details on the DataTable class, which involves the DataColumn and DataRow classes mentioned.
DataTable ExamplesSummary
We looked at the DataColumn class in the C# language and the .NET Framework, found in the System.Data namespace. The DataColumn acts as a template for the in-memory relational database abstraction specified by the DataTable type.
Data- C# DataColumn
- DataColumn
- C# DataSet、DataTable、DataRow、DataColumn 数据集应用大全
- C# DataSet、DataTable、DataRow、DataColumn 数据集应用大全
- c# DataSet DataTable DataColumn DataRow数据操作集
- C#新建DataColumn类时Type类型参数的生成方式
- C# DataSet、DataTable、DataRow、DataColumn 数据集应用大全
- C# DataSet、DataTable、DataRow、DataColumn 数据集应用大全
- C# DataSet、DataTable、DataRow、DataColumn 数据集应用大全
- C#中 DataSet、DataTable、DataRow、DataColumn区别及使用实例
- DataColumn 类
- DataColumn 类
- [gridView] -- DataColumn
- DataColumn 对象
- 深入浅出C#2008从入门到提高Step By Step(七)数据访问(5)-DataColumn
- DataColumn.Expression 属性
- DataColumn.Expression 属性 [C#]
- DataColumn 对象之概述
- C Programming Language 1-14
- java编程将HTML文件转换成PDF文件
- HDU-1258(DFS搜索的问题)
- DataGridView取消默认选中行
- 编程珠玑第二章
- C# DataColumn
- D3D9 vs D3D1x
- 深入浅出FPGA-1-Cyclone芯片内部
- NET Win HTML Editor Control破解过程全记录
- Cosmos开发指南(一)
- 黑马程序员-java中的枚举
- svn命令使用手册
- Install Magento on Ubuntu
- DirectCompute & DirectX 11 计算着色器编程简介