DataTable 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示内存中数据的一个表。
public ref class DataTable : System::ComponentModel::MarshalByValueComponent, System::ComponentModel::IListSource, System::ComponentModel::ISupportInitialize, System::ComponentModel::ISupportInitializeNotification, System::Runtime::Serialization::ISerializable, System::Xml::Serialization::IXmlSerializable
public ref class DataTable
public ref class DataTable : System::ComponentModel::MarshalByValueComponent, System::ComponentModel::IListSource, System::ComponentModel::ISupportInitialize, System::Runtime::Serialization::ISerializable
public ref class DataTable : System::ComponentModel::MarshalByValueComponent, System::ComponentModel::IListSource, System::ComponentModel::ISupportInitializeNotification, System::Runtime::Serialization::ISerializable, System::Xml::Serialization::IXmlSerializable
public class DataTable : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitialize, System.ComponentModel.ISupportInitializeNotification, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
public class DataTable
[System.Serializable]
public class DataTable : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitialize, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class DataTable : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitializeNotification, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
public class DataTable : System.ComponentModel.MarshalByValueComponent, System.ComponentModel.IListSource, System.ComponentModel.ISupportInitializeNotification, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
type DataTable = class
inherit MarshalByValueComponent
interface IListSource
interface ISupportInitialize
interface ISupportInitializeNotification
interface ISerializable
interface IXmlSerializable
type DataTable = class
[<System.Serializable>]
type DataTable = class
inherit MarshalByValueComponent
interface IListSource
interface ISupportInitialize
interface ISerializable
[<System.Serializable>]
type DataTable = class
inherit MarshalByValueComponent
interface IListSource
interface ISupportInitializeNotification
interface ISupportInitialize
interface ISerializable
interface IXmlSerializable
[<System.Serializable>]
type DataTable = class
inherit MarshalByValueComponent
interface IListSource
interface ISupportInitializeNotification
interface ISerializable
interface IXmlSerializable
interface ISupportInitialize
Public Class DataTable
Inherits MarshalByValueComponent
Implements IListSource, ISerializable, ISupportInitialize, ISupportInitializeNotification, IXmlSerializable
Public Class DataTable
Public Class DataTable
Inherits MarshalByValueComponent
Implements IListSource, ISerializable, ISupportInitialize
Public Class DataTable
Inherits MarshalByValueComponent
Implements IListSource, ISerializable, ISupportInitializeNotification, IXmlSerializable
- 继承
- 继承
-
DataTable
- 派生
- 属性
- 实现
示例
以下示例创建两 DataTable 个对象和一个 DataRelation 对象,并将新对象添加到一个 DataSet对象。 然后,表会显示在控件中 DataGridView 。
// Put the next line into the Declarations section.
private System.Data.DataSet dataSet;
private void MakeDataTables()
{
// Run all of the functions.
MakeParentTable();
MakeChildTable();
MakeDataRelation();
BindToDataGrid();
}
private void MakeParentTable()
{
// Create a new DataTable.
System.Data.DataTable table = new DataTable("ParentTable");
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType,
// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
column.ReadOnly = true;
column.Unique = true;
// Add the Column to the DataColumnCollection.
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "ParentItem";
column.AutoIncrement = false;
column.Caption = "ParentItem";
column.ReadOnly = false;
column.Unique = false;
// Add the column to the table.
table.Columns.Add(column);
// Make the ID column the primary key column.
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns["id"];
table.PrimaryKey = PrimaryKeyColumns;
// Instantiate the DataSet variable.
dataSet = new DataSet();
// Add the new DataTable to the DataSet.
dataSet.Tables.Add(table);
// Create three new DataRow objects and add
// them to the DataTable
for (int i = 0; i <= 2; i++)
{
row = table.NewRow();
row["id"] = i;
row["ParentItem"] = "ParentItem " + i;
table.Rows.Add(row);
}
}
private void MakeChildTable()
{
// Create a new DataTable.
DataTable table = new DataTable("childTable");
DataColumn column;
DataRow row;
// Create first column and add to the DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "ChildID";
column.AutoIncrement = true;
column.Caption = "ID";
column.ReadOnly = true;
column.Unique = true;
// Add the column to the DataColumnCollection.
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "ChildItem";
column.AutoIncrement = false;
column.Caption = "ChildItem";
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
// Create third column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "ParentID";
column.AutoIncrement = false;
column.Caption = "ParentID";
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
dataSet.Tables.Add(table);
// Create three sets of DataRow objects,
// five rows each, and add to DataTable.
for (int i = 0; i <= 4; i++)
{
row = table.NewRow();
row["childID"] = i;
row["ChildItem"] = "Item " + i;
row["ParentID"] = 0;
table.Rows.Add(row);
}
for (int i = 0; i <= 4; i++)
{
row = table.NewRow();
row["childID"] = i + 5;
row["ChildItem"] = "Item " + i;
row["ParentID"] = 1;
table.Rows.Add(row);
}
for (int i = 0; i <= 4; i++)
{
row = table.NewRow();
row["childID"] = i + 10;
row["ChildItem"] = "Item " + i;
row["ParentID"] = 2;
table.Rows.Add(row);
}
}
private void MakeDataRelation()
{
// DataRelation requires two DataColumn
// (parent and child) and a name.
DataColumn parentColumn =
dataSet.Tables["ParentTable"].Columns["id"];
DataColumn childColumn =
dataSet.Tables["ChildTable"].Columns["ParentID"];
DataRelation relation = new
DataRelation("parent2Child", parentColumn, childColumn);
dataSet.Tables["ChildTable"].ParentRelations.Add(relation);
}
private void BindToDataGrid()
{
// Instruct the DataGrid to bind to the DataSet, with the
// ParentTable as the topmost DataTable.
DataGrid1.SetDataBinding(dataSet, "ParentTable");
}
' Put the next line into the Declarations section.
private dataSet As DataSet
Private Sub MakeDataTables()
' Run all of the functions.
MakeParentTable()
MakeChildTable()
MakeDataRelation()
BindToDataGrid()
End Sub
Private Sub MakeParentTable()
' Create a new DataTable.
Dim table As New DataTable("ParentTable")
' Declare variables for DataColumn and DataRow objects.
Dim column As DataColumn
Dim row As DataRow
' Create new DataColumn, set DataType, ColumnName
' and add to DataTable.
column = New DataColumn()
column.DataType = System.Type.GetType("System.Int32")
column.ColumnName = "id"
column.ReadOnly = True
column.Unique = True
' Add the Column to the DataColumnCollection.
table.Columns.Add(column)
' Create second column.
column = New DataColumn()
column.DataType = System.Type.GetType("System.String")
column.ColumnName = "ParentItem"
column.AutoIncrement = False
column.Caption = "ParentItem"
column.ReadOnly = False
column.Unique = False
' Add the column to the table.
table.Columns.Add(column)
' Make the ID column the primary key column.
Dim PrimaryKeyColumns(0) As DataColumn
PrimaryKeyColumns(0)= table.Columns("id")
table.PrimaryKey = PrimaryKeyColumns
' Instantiate the DataSet variable.
dataSet = New DataSet()
' Add the new DataTable to the DataSet.
dataSet.Tables.Add(table)
' Create three new DataRow objects and add
' them to the DataTable
Dim i As Integer
For i = 0 to 2
row = table.NewRow()
row("id") = i
row("ParentItem") = "ParentItem " + i.ToString()
table.Rows.Add(row)
Next i
End Sub
Private Sub MakeChildTable()
' Create a new DataTable.
Dim table As New DataTable("childTable")
Dim column As DataColumn
Dim row As DataRow
' Create first column and add to the DataTable.
column = New DataColumn()
column.DataType= System.Type.GetType("System.Int32")
column.ColumnName = "ChildID"
column.AutoIncrement = True
column.Caption = "ID"
column.ReadOnly = True
column.Unique = True
' Add the column to the DataColumnCollection.
table.Columns.Add(column)
' Create second column.
column = New DataColumn()
column.DataType= System.Type.GetType("System.String")
column.ColumnName = "ChildItem"
column.AutoIncrement = False
column.Caption = "ChildItem"
column.ReadOnly = False
column.Unique = False
table.Columns.Add(column)
' Create third column.
column = New DataColumn()
column.DataType= System.Type.GetType("System.Int32")
column.ColumnName = "ParentID"
column.AutoIncrement = False
column.Caption = "ParentID"
column.ReadOnly = False
column.Unique = False
table.Columns.Add(column)
dataSet.Tables.Add(table)
' Create three sets of DataRow objects, five rows each,
' and add to DataTable.
Dim i As Integer
For i = 0 to 4
row = table.NewRow()
row("childID") = i
row("ChildItem") = "Item " + i.ToString()
row("ParentID") = 0
table.Rows.Add(row)
Next i
For i = 0 to 4
row = table.NewRow()
row("childID") = i + 5
row("ChildItem") = "Item " + i.ToString()
row("ParentID") = 1
table.Rows.Add(row)
Next i
For i = 0 to 4
row = table.NewRow()
row("childID") = i + 10
row("ChildItem") = "Item " + i.ToString()
row("ParentID") = 2
table.Rows.Add(row)
Next i
End Sub
Private Sub MakeDataRelation()
' DataRelation requires two DataColumn
' (parent and child) and a name.
Dim parentColumn As DataColumn = _
dataSet.Tables("ParentTable").Columns("id")
Dim childColumn As DataColumn = _
dataSet.Tables("ChildTable").Columns("ParentID")
Dim relation As DataRelation = new _
DataRelation("parent2Child", parentColumn, childColumn)
dataSet.Tables("ChildTable").ParentRelations.Add(relation)
End Sub
Private Sub BindToDataGrid()
' Instruct the DataGrid to bind to the DataSet, with the
' ParentTable as the topmost DataTable.
DataGrid1.SetDataBinding(dataSet,"ParentTable")
End Sub
此示例演示如何使用特定的架构定义手动创建 DataTable:
创建多个 DataTable 并定义初始列。
创建表约束。
插入值并显示表。
创建表达式列并显示表。
using System;
using System.Data;
class Program
{
static void Main(string[] args)
{
// Create two tables and add them into the DataSet
DataTable orderTable = CreateOrderTable();
DataTable orderDetailTable = CreateOrderDetailTable();
DataSet salesSet = new DataSet();
salesSet.Tables.Add(orderTable);
salesSet.Tables.Add(orderDetailTable);
// Set the relations between the tables and create the related constraint.
salesSet.Relations.Add("OrderOrderDetail", orderTable.Columns["OrderId"], orderDetailTable.Columns["OrderId"], true);
Console.WriteLine("After creating the foreign key constriant, you will see the following error if inserting order detail with the wrong OrderId: ");
try
{
DataRow errorRow = orderDetailTable.NewRow();
errorRow[0] = 1;
errorRow[1] = "O0007";
orderDetailTable.Rows.Add(errorRow);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine();
// Insert the rows into the table
InsertOrders(orderTable);
InsertOrderDetails(orderDetailTable);
Console.WriteLine("The initial Order table.");
ShowTable(orderTable);
Console.WriteLine("The OrderDetail table.");
ShowTable(orderDetailTable);
// Use the Aggregate-Sum on the child table column to get the result.
DataColumn colSub = new DataColumn("SubTotal", typeof(Decimal), "Sum(Child.LineTotal)");
orderTable.Columns.Add(colSub);
// Compute the tax by referencing the SubTotal expression column.
DataColumn colTax = new DataColumn("Tax", typeof(Decimal), "SubTotal*0.1");
orderTable.Columns.Add(colTax);
// If the OrderId is 'Total', compute the due on all orders; or compute the due on this order.
DataColumn colTotal = new DataColumn("TotalDue", typeof(Decimal), "IIF(OrderId='Total',Sum(SubTotal)+Sum(Tax),SubTotal+Tax)");
orderTable.Columns.Add(colTotal);
DataRow row = orderTable.NewRow();
row["OrderId"] = "Total";
orderTable.Rows.Add(row);
Console.WriteLine("The Order table with the expression columns.");
ShowTable(orderTable);
Console.WriteLine("Press any key to exit.....");
Console.ReadKey();
}
private static DataTable CreateOrderTable()
{
DataTable orderTable = new DataTable("Order");
// Define one column.
DataColumn colId = new DataColumn("OrderId", typeof(String));
orderTable.Columns.Add(colId);
DataColumn colDate = new DataColumn("OrderDate", typeof(DateTime));
orderTable.Columns.Add(colDate);
// Set the OrderId column as the primary key.
orderTable.PrimaryKey = new DataColumn[] { colId };
return orderTable;
}
private static DataTable CreateOrderDetailTable()
{
DataTable orderDetailTable = new DataTable("OrderDetail");
// Define all the columns once.
DataColumn[] cols =
{
new DataColumn("OrderDetailId", typeof(Int32)),
new DataColumn("OrderId", typeof(String)),
new DataColumn("Product", typeof(String)),
new DataColumn("UnitPrice", typeof(Decimal)),
new DataColumn("OrderQty", typeof(Int32)),
new DataColumn("LineTotal", typeof(Decimal), "UnitPrice*OrderQty")
};
orderDetailTable.Columns.AddRange(cols);
orderDetailTable.PrimaryKey = new DataColumn[] { orderDetailTable.Columns["OrderDetailId"] };
return orderDetailTable;
}
private static void InsertOrders(DataTable orderTable)
{
// Add one row once.
DataRow row1 = orderTable.NewRow();
row1["OrderId"] = "O0001";
row1["OrderDate"] = new DateTime(2013, 3, 1);
orderTable.Rows.Add(row1);
DataRow row2 = orderTable.NewRow();
row2["OrderId"] = "O0002";
row2["OrderDate"] = new DateTime(2013, 3, 12);
orderTable.Rows.Add(row2);
DataRow row3 = orderTable.NewRow();
row3["OrderId"] = "O0003";
row3["OrderDate"] = new DateTime(2013, 3, 20);
orderTable.Rows.Add(row3);
}
private static void InsertOrderDetails(DataTable orderDetailTable)
{
// Use an Object array to insert all the rows .
// Values in the array are matched sequentially to the columns, based on the order in which they appear in the table.
Object[] rows =
{
new Object[] { 1, "O0001", "Mountain Bike", 1419.5, 36 },
new Object[] { 2, "O0001", "Road Bike", 1233.6, 16 },
new Object[] { 3, "O0001", "Touring Bike", 1653.3, 32 },
new Object[] { 4, "O0002", "Mountain Bike", 1419.5, 24 },
new Object[] { 5, "O0002", "Road Bike", 1233.6, 12 },
new Object[] { 6, "O0003", "Mountain Bike", 1419.5, 48 },
new Object[] { 7, "O0003", "Touring Bike", 1653.3, 8 },
};
foreach (Object[] row in rows)
{
orderDetailTable.Rows.Add(row);
}
}
private static void ShowTable(DataTable table)
{
foreach (DataColumn col in table.Columns)
{
Console.Write("{0,-14}", col.ColumnName);
}
Console.WriteLine();
foreach (DataRow row in table.Rows)
{
foreach (DataColumn col in table.Columns)
{
if (col.DataType.Equals(typeof(DateTime)))
Console.Write("{0,-14:d}", row[col]);
else if (col.DataType.Equals(typeof(Decimal)))
Console.Write("{0,-14:C}", row[col]);
else
Console.Write("{0,-14}", row[col]);
}
Console.WriteLine();
}
Console.WriteLine();
}
}
Imports System.Data
Class Program
Public Shared Sub Main(args As String())
' Create two tables and add them into the DataSet
Dim orderTable As DataTable = CreateOrderTable()
Dim orderDetailTable As DataTable = CreateOrderDetailTable()
Dim salesSet As New DataSet()
salesSet.Tables.Add(orderTable)
salesSet.Tables.Add(orderDetailTable)
' Set the relations between the tables and create the related constraint.
salesSet.Relations.Add("OrderOrderDetail", orderTable.Columns("OrderId"), orderDetailTable.Columns("OrderId"), True)
Console.WriteLine("After creating the foreign key constriant, you will see the following error if inserting order detail with the wrong OrderId: ")
Try
Dim errorRow As DataRow = orderDetailTable.NewRow()
errorRow(0) = 1
errorRow(1) = "O0007"
orderDetailTable.Rows.Add(errorRow)
Catch e As Exception
Console.WriteLine(e.Message)
End Try
Console.WriteLine()
' Insert the rows into the table
InsertOrders(orderTable)
InsertOrderDetails(orderDetailTable)
Console.WriteLine("The initial Order table.")
ShowTable(orderTable)
Console.WriteLine("The OrderDetail table.")
ShowTable(orderDetailTable)
' Use the Aggregate-Sum on the child table column to get the result.
Dim colSub As New DataColumn("SubTotal", GetType([Decimal]), "Sum(Child.LineTotal)")
orderTable.Columns.Add(colSub)
' Compute the tax by referencing the SubTotal expression column.
Dim colTax As New DataColumn("Tax", GetType([Decimal]), "SubTotal*0.1")
orderTable.Columns.Add(colTax)
' If the OrderId is 'Total', compute the due on all orders; or compute the due on this order.
Dim colTotal As New DataColumn("TotalDue", GetType([Decimal]), "IIF(OrderId='Total',Sum(SubTotal)+Sum(Tax),SubTotal+Tax)")
orderTable.Columns.Add(colTotal)
Dim row As DataRow = orderTable.NewRow()
row("OrderId") = "Total"
orderTable.Rows.Add(row)
Console.WriteLine("The Order table with the expression columns.")
ShowTable(orderTable)
Console.WriteLine("Press any key to exit.....")
Console.ReadKey()
End Sub
Private Shared Function CreateOrderTable() As DataTable
Dim orderTable As New DataTable("Order")
' Define one column.
Dim colId As New DataColumn("OrderId", GetType([String]))
orderTable.Columns.Add(colId)
Dim colDate As New DataColumn("OrderDate", GetType(DateTime))
orderTable.Columns.Add(colDate)
' Set the OrderId column as the primary key.
orderTable.PrimaryKey = New DataColumn() {colId}
Return orderTable
End Function
Private Shared Function CreateOrderDetailTable() As DataTable
Dim orderDetailTable As New DataTable("OrderDetail")
' Define all the columns once.
Dim cols As DataColumn() = {New DataColumn("OrderDetailId", GetType(Int32)), New DataColumn("OrderId", GetType([String])), New DataColumn("Product", GetType([String])), New DataColumn("UnitPrice", GetType([Decimal])), New DataColumn("OrderQty", GetType(Int32)), New DataColumn("LineTotal", GetType([Decimal]), "UnitPrice*OrderQty")}
orderDetailTable.Columns.AddRange(cols)
orderDetailTable.PrimaryKey = New DataColumn() {orderDetailTable.Columns("OrderDetailId")}
Return orderDetailTable
End Function
Private Shared Sub InsertOrders(orderTable As DataTable)
' Add one row once.
Dim row1 As DataRow = orderTable.NewRow()
row1("OrderId") = "O0001"
row1("OrderDate") = New DateTime(2013, 3, 1)
orderTable.Rows.Add(row1)
Dim row2 As DataRow = orderTable.NewRow()
row2("OrderId") = "O0002"
row2("OrderDate") = New DateTime(2013, 3, 12)
orderTable.Rows.Add(row2)
Dim row3 As DataRow = orderTable.NewRow()
row3("OrderId") = "O0003"
row3("OrderDate") = New DateTime(2013, 3, 20)
orderTable.Rows.Add(row3)
End Sub
Private Shared Sub InsertOrderDetails(orderDetailTable As DataTable)
' Use an Object array to insert all the rows .
' Values in the array are matched sequentially to the columns, based on the order in which they appear in the table.
Dim rows As [Object]() = {New [Object]() {1, "O0001", "Mountain Bike", 1419.5, 36}, New [Object]() {2, "O0001", "Road Bike", 1233.6, 16}, New [Object]() {3, "O0001", "Touring Bike", 1653.3, 32}, New [Object]() {4, "O0002", "Mountain Bike", 1419.5, 24}, New [Object]() {5, "O0002", "Road Bike", 1233.6, 12}, New [Object]() {6, "O0003", "Mountain Bike", 1419.5, 48}, _
New [Object]() {7, "O0003", "Touring Bike", 1653.3, 8}}
For Each row As [Object]() In rows
orderDetailTable.Rows.Add(row)
Next
End Sub
Private Shared Sub ShowTable(table As DataTable)
For Each col As DataColumn In table.Columns
Console.Write("{0,-14}", col.ColumnName)
Next
Console.WriteLine()
For Each row As DataRow In table.Rows
For Each col As DataColumn In table.Columns
If col.DataType.Equals(GetType(DateTime)) Then
Console.Write("{0,-14:d}", row(col))
ElseIf col.DataType.Equals(GetType([Decimal])) Then
Console.Write("{0,-14:C}", row(col))
Else
Console.Write("{0,-14}", row(col))
End If
Next
Console.WriteLine()
Next
Console.WriteLine()
End Sub
End Class
注解
DataTable这是 ADO.NET 库中的中心对象。 使用 DataTable include DataSet 和 the DataView.
访问 DataTable 对象时,请注意它们有条件区分大小写。 例如,如果一个 DataTable 名为“mydatatable”,另一个名为“Mydatatable”,则用于搜索其中一个表的字符串被视为区分大小写。 但是,如果“mydatatable”存在且“Mydatatable”不存在,则搜索字符串被视为不区分大小写。 A DataSet 可以包含两DataTableTableName个具有相同属性值但不同Namespace属性值的对象。 有关使用 DataTable 对象的详细信息,请参阅 创建 DataTable。
如果要以编程方式创建 DataTable 架构,必须先通过将对象添加到 DataColumn DataColumnCollection 通过 Columns 属性) 访问的 (来定义其架构。 有关添加 DataColumn 对象的详细信息,请参阅 向 DataTable 添加列。
若要向 a DataTable添加行,必须先使用 NewRow 该方法返回新 DataRow 对象。 该方法 NewRow 返回具有架构的 DataTable行,因为它由表的定义 DataColumnCollection。 可存储的最大行 DataTable 数为 16,777,216。 有关详细信息,请参阅 将数据添加到 DataTable。
它还 DataTable 包含可用于确保数据完整性的对象集合 Constraint 。 有关详细信息,请参阅DataTable 约束。
有许多 DataTable 事件可用于确定何时对表进行更改。 其中包括 RowChanged、RowChanging、RowDeleting 和 RowDeleted。 有关可用于 a DataTable的事件的详细信息,请参阅 处理 DataTable 事件。
创建实例 DataTable 时,某些读/写属性设置为初始值。 有关这些值的列表,请参阅 DataTable.DataTable 构造函数主题。
备注
这些DataSet对象DataTable继承MarshalByValueComponent自并支持ISerializable.NET Framework远程处理接口。 以下是可用于.NET Framework远程处理的唯一 ADO.NET 对象。
安全注意事项
有关 DataSet 和 DataTable 安全性的信息,请参阅 安全指南。
构造函数
DataTable() |
在不使用参数的情况下初始化 DataTable 类的新实例。 |
DataTable(SerializationInfo, StreamingContext) |
用序列化数据初始化 DataTable 类的新实例。 |
DataTable(String) |
使用指定的表名初始化 DataTable 类的新实例。 |
DataTable(String, String) |
使用指定的表名和命名空间初始化 DataTable 类的新实例。 |
字段
fInitInProgress |
检查是否正在进行初始化。 初始化发生在运行时。 |
属性
CaseSensitive |
指示表中的字符串比较是否区分大小写。 |
ChildRelations |
获取此 DataTable 的子关系的集合。 |
Columns |
获取属于该表的列的集合。 |
Constraints |
获取由该表维护的约束的集合。 |
Container |
获取组件的容器。 (继承自 MarshalByValueComponent) |
DataSet |
获取此表所属的 DataSet。 |
DefaultView |
获取可能包含筛选视图或游标位置的表的自定义视图。 |
DesignMode |
获取指示组件当前是否处于设计模式的值。 (继承自 MarshalByValueComponent) |
DisplayExpression |
获取或设置一个表达式,该表达式返回的值用于在用户界面中表示此表。 |
Events |
获取附加到该组件的事件处理程序的列表。 (继承自 MarshalByValueComponent) |
ExtendedProperties |
获取自定义用户信息的集合。 |
HasErrors |
获取一个值,该值指示该表所属的 DataSet 的任何表的任何行中是否有错误。 |
IsInitialized |
获取一个值,该值指示是否已初始化 DataTable。 |
Locale |
获取或设置用于比较表中字符串的区域设置信息。 |
MinimumCapacity |
获取或设置该表最初的起始大小。 |
Namespace |
获取或设置 DataTable 中所存储数据的 XML 表示形式的命名空间。 |
ParentRelations |
获取该 DataTable 的父关系的集合。 |
Prefix |
获取或设置 DataTable 中所存储数据的 XML 表示形式的命名空间。 |
PrimaryKey |
获取或设置用作数据表主键的列数组。 |
RemotingFormat |
获取或设置序列化格式。 |
Rows |
获取属于该表的行的集合。 |
Site | |
TableName |
获取或设置 DataTable 的名称。 |
方法
事件
ColumnChanged |
更改 DataRow 中指定的 DataColumn 值之后发生。 |
ColumnChanging |
更改 DataRow 中指定的 DataColumn 值时发生。 |
Disposed |
添加用于侦听组件的 Disposed 事件的事件处理程序。 (继承自 MarshalByValueComponent) |
Initialized |
初始化 DataTable 后发生。 |
RowChanged |
在成功更改 DataRow 后发生。 |
RowChanging |
在更改 DataRow 时发生。 |
RowDeleted |
删除表中的行后发生。 |
RowDeleting |
要删除表中的行之前发生。 |
TableCleared |
清除 DataTable 后发生。 |
TableClearing |
清除 DataTable 时发生。 |
TableNewRow |
插入新的 DataRow 时发生。 |
显式接口实现
IListSource.ContainsListCollection |
有关此成员的说明,请参见 ContainsListCollection。 |
IListSource.GetList() |
有关此成员的说明,请参见 GetList()。 |
ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
使用序列化 DataTable 时所需的数据填充序列化信息对象。 |
IXmlSerializable.GetSchema() |
有关此成员的说明,请参见 GetSchema()。 |
IXmlSerializable.ReadXml(XmlReader) |
有关此成员的说明,请参见 ReadXml(XmlReader)。 |
IXmlSerializable.WriteXml(XmlWriter) |
有关此成员的说明,请参见 WriteXml(XmlWriter)。 |
扩展方法
AsDataView(DataTable) |
创建并返回支持 LINQ 的 DataView 对象。 |
AsEnumerable(DataTable) |
返回一个 IEnumerable<T> 对象,其泛型参数 |
适用于
线程安全性
此类型对于多线程读取操作是安全的。 必须同步任何写入操作。