DataTable 类

定义

表示一个内存中数据表。

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
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
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.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
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)>]
type DataTable = class
    inherit MarshalByValueComponent
    interface IListSource
    interface ISupportInitialize
    interface ISupportInitializeNotification
    interface ISerializable
    interface 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
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:

  • 创建多个 DataTable 并定义初始列。
  • 创建表约束。
  • 插入值并显示表。
  • 创建表达式列并显示表。
using System;
using System.Data;

class Program
{
    static void Main()
    {
        // Create two tables and add them into the DataSet.
        DataTable orderTable = CreateOrderTable();
        DataTable orderDetailTable = CreateOrderDetailTable();
        DataSet salesSet = new();
        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 constraint, " +
            "you'll see the following error if you insert " +
            "an order detail with the wrong OrderId:\n");
        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("SubTotal", typeof(decimal), "Sum(Child.LineTotal)");
        orderTable.Columns.Add(colSub);

        // Compute the tax by referencing the SubTotal expression column.
        DataColumn colTax = new("Tax", typeof(decimal), "SubTotal*0.1");
        orderTable.Columns.Add(colTax);

        // If the OrderId is 'Total', compute the amount due on all orders; otherwise, compute the amount due on this order.
        DataColumn colTotal = new(
            "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("Order");

        // Define the columns one at a time.
        DataColumn colId = new("OrderId", typeof(string));
        orderTable.Columns.Add(colId);

        DataColumn colDate = new("OrderDate", typeof(DateTime));
        orderTable.Columns.Add(colDate);

        // Set the OrderId column as the primary key.
        orderTable.PrimaryKey = [colId];

        return orderTable;
    }

    private static DataTable CreateOrderDetailTable()
    {
        DataTable orderDetailTable = new("OrderDetail");

        // Define all the columns at once.
        DataColumn[] cols =
        [
            new DataColumn("OrderDetailId", typeof(int)),
            new DataColumn("OrderId", typeof(string)),
            new DataColumn("Product", typeof(string)),
            new DataColumn("UnitPrice", typeof(decimal)),
            new DataColumn("OrderQty", typeof(int)),
            new DataColumn("LineTotal", typeof(decimal), "UnitPrice*OrderQty")
        ];

        orderDetailTable.Columns.AddRange(cols);
        orderDetailTable.PrimaryKey = [orderDetailTable.Columns["OrderDetailId"]];
        return orderDetailTable;
    }

    private static void InsertOrders(DataTable orderTable)
    {
        // Add one row at a time.
        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 =
        [
            [1, "O0001", "Mountain Bike", 1419.5, 36],
            [2, "O0001", "Road Bike", 1233.6, 16],
            [3, "O0001", "Touring Bike", 1653.3, 32],
            [4, "O0002", "Mountain Bike", 1419.5, 24],
            [5, "O0002", "Road Bike", 1233.6, 12],
            [6, "O0003", "Mountain Bike", 1419.5, 48],
            [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();
    }
}
' 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 类是 ADO.NET 库中的中心对象。 使用 DataTable 的其他对象包括 DataSetDataView.

DataTable 对象名称在特定条件下区分大小写。 例如,如果一个 DataTable 名为“mydatatable”,另一个名为“Mydatatable”,则用于搜索其中一个表的字符串被认为区分大小写。 但是,如果“mydatatable”存在且“Mydatatable”不存在,则搜索字符串被视为不区分大小写。 A DataSet 可以包含两 DataTable 个具有相同 TableName 属性值但不同 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 事件可用于确定何时对表进行更改。 这些包括 RowChangedRowChangingRowDeletingRowDeleted。 有关可以与DataTable一起使用的事件的详细信息,请参阅处理 DataTable 事件

创建实例 DataTable 时,某些读/写属性将设置为初始值。 有关这些值的列表,请参阅 DataTable 构造函数。

注释

DataSetDataTable对象继承自MarshalByValueComponent并支持 .NET 远程接口ISerializable。 这些是可用于 .NET 远程处理的唯一 ADO.NET 对象。

安全注意事项

有关 DataSet 和 DataTable 安全性的信息,请参阅 安全指南

构造函数

名称 说明
DataTable()

初始化没有参数的 DataTable 类的新实例。

DataTable(SerializationInfo, StreamingContext)
已过时.

使用序列化的数据初始化 DataTable 类的新实例。

DataTable(String, String)

使用指定的表名称和命名空间初始化类的新实例 DataTable

DataTable(String)

使用指定的表名称初始化类的新实例 DataTable

字段

名称 说明
fInitInProgress

检查初始化是否正在进行。 初始化在运行时发生。

属性

名称 说明
CaseSensitive

指示表中的字符串比较是否区分大小写。

ChildRelations

获取此 DataTable子关系的集合。

Columns

获取属于此表的列的集合。

Constraints

获取此表维护的约束的集合。

Container

获取组件的容器。

(继承自 MarshalByValueComponent)
DataSet

DataSet获取此表所属的项。

DefaultView

获取可能包含筛选视图或游标位置的表的自定义视图。

DesignMode

获取一个值,该值指示组件当前是否处于设计模式。

(继承自 MarshalByValueComponent)
DisplayExpression

获取或设置返回用于在用户界面中表示此表的值的表达式。 使用该 DisplayExpression 属性可以在用户界面中显示此表的名称。

Events

获取附加到此组件的事件处理程序的列表。

(继承自 MarshalByValueComponent)
ExtendedProperties

获取自定义用户信息的集合。

HasErrors

获取一个值,该值指示表所属的任何表中 DataSet 是否有错误。

IsInitialized

获取一个值,该值指示是否已 DataTable 初始化。

Locale

获取或设置用于比较表中字符串的区域设置信息。

MinimumCapacity

获取或设置此表的初始起始大小。

Namespace

获取或设置存储在 .. 中的 DataTable数据的 XML 表示形式的命名空间。

ParentRelations

获取此 DataTable对象的父关系集合。

Prefix

获取或设置存储在 .. 中的 DataTable数据的 XML 表示形式的命名空间。

PrimaryKey

获取或设置作为数据表主键的列数组。

RemotingFormat

获取或设置序列化格式。

Rows

获取属于此表的行的集合。

Site

获取或设置一ISiteDataTable用于 .

TableName

获取或设置 . 的名称 DataTable

方法

名称 说明
AcceptChanges()

提交自上次 AcceptChanges() 调用以来对此表所做的所有更改。

BeginInit()

DataTable开始初始化窗体或由另一个组件使用的初始化。 初始化在运行时发生。

BeginLoadData()

在加载数据时关闭通知、索引维护和约束。

Clear()

清除 DataTable 所有数据。

Clone()

DataTable克隆结构,包括所有DataTable架构和约束。

Compute(String, String)

对传递筛选条件的当前行计算给定表达式。

Copy()

复制此 DataTable对象的结构和数据。

CreateDataReader()

返回与此中的数据DataTableReader对应的值DataTable

CreateInstance()

创建 DataTable的新实例。

Dispose()

释放该 MarshalByValueComponent命令使用的所有资源。

(继承自 MarshalByValueComponent)
Dispose(Boolean)

释放由托管资源使用 MarshalByValueComponent 的非托管资源,并选择性地释放托管资源。

(继承自 MarshalByValueComponent)
EndInit()

结束在窗体上使用或 DataTable 由另一个组件使用的初始化。 初始化在运行时发生。

EndLoadData()

在加载数据后打开通知、索引维护和约束。

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetChanges()

获取包含自加载或DataTable上次调用以来对它所做的所有更改的副本AcceptChanges()

GetChanges(DataRowState)

获取一个副本,DataTable其中包含自上次加载以来对它所做的所有更改的副本,或AcceptChanges()自调用后,按筛选。DataRowState

GetDataTableSchema(XmlSchemaSet)

此方法返回一个XmlSchemaSet实例,该实例包含描述 Web 服务的 Web 服务描述语言(WSDL)。DataTable

GetErrors()

获取包含错误的对象的数组 DataRow

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetObjectData(SerializationInfo, StreamingContext)
已过时.

使用序列化 DataTable所需的数据填充序列化信息对象。

GetRowType()

获取行类型。

GetSchema()

有关此成员的说明,请参阅 GetSchema()

GetService(Type)

获取 . 的 IServiceProvider实现者。

(继承自 MarshalByValueComponent)
GetType()

获取当前实例的 Type

(继承自 Object)
ImportRow(DataRow)

将 a 复制到一个DataRowDataTable、保留任何属性设置以及原始值和当前值。

Load(IDataReader, LoadOption, FillErrorEventHandler)

DataTable使用错误处理委托提供的IDataReader数据源中的值填充值。

Load(IDataReader, LoadOption)

DataTable使用提供的IDataReader数据源中的值填充值。 DataTable如果已包含行,则数据源中的传入数据会根据参数的值loadOption与现有行合并。

Load(IDataReader)

DataTable使用提供的IDataReader数据源中的值填充值。 DataTable如果已包含行,则数据源中的传入数据将与现有行合并。

LoadDataRow(Object[], Boolean)

查找并更新特定行。 如果未找到匹配的行,则会使用给定值创建新行。

LoadDataRow(Object[], LoadOption)

查找并更新特定行。 如果未找到匹配的行,则会使用给定值创建新行。

MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
Merge(DataTable, Boolean, MissingSchemaAction)

将指定的 DataTable 项与当前 DataTable合并,指示是否保留更改以及如何处理当前 DataTable中缺少的架构。

Merge(DataTable, Boolean)

将指定的 DataTable 值与当前 DataTable合并,指示是否保留当前 DataTable更改。

Merge(DataTable)

将指定的 DataTable 值与当前 DataTable合并 。

NewRow()

创建与表相同的架构的新 DataRow 项。

NewRowArray(Int32)

返回数 DataRow组。

NewRowFromBuilder(DataRowBuilder)

从现有行创建新行。

OnColumnChanged(DataColumnChangeEventArgs)

引发 ColumnChanged 事件。

OnColumnChanging(DataColumnChangeEventArgs)

引发 ColumnChanging 事件。

OnPropertyChanging(PropertyChangedEventArgs)

引发 PropertyChanged 事件。

OnRemoveColumn(DataColumn)

通知 DataTable 正在删除 a DataColumn

OnRowChanged(DataRowChangeEventArgs)

引发 RowChanged 事件。

OnRowChanging(DataRowChangeEventArgs)

引发 RowChanging 事件。

OnRowDeleted(DataRowChangeEventArgs)

引发 RowDeleted 事件。

OnRowDeleting(DataRowChangeEventArgs)

引发 RowDeleting 事件。

OnTableCleared(DataTableClearEventArgs)

引发 TableCleared 事件。

OnTableClearing(DataTableClearEventArgs)

引发 TableClearing 事件。

OnTableNewRow(DataTableNewRowEventArgs)

引发 TableNewRow 事件。

ReadXml(Stream)

使用指定的DataTable对象读取 XML 架构和数据Stream

ReadXml(String)

从指定文件中读取 XML 架构和数据 DataTable

ReadXml(TextReader)

使用指定的DataTable对象读取 XML 架构和数据TextReader

ReadXml(XmlReader)

使用指定的DataTable对象读取 XML 架构和数据XmlReader

ReadXmlSchema(Stream)

使用指定的流将 XML 架构读入 DataTable 该架构。

ReadXmlSchema(String)

从指定文件中读取 XML 架构 DataTable

ReadXmlSchema(TextReader)

使用指定的DataTable对象读取 XML 架构TextReader

ReadXmlSchema(XmlReader)

使用指定的DataTable对象读取 XML 架构XmlReader

ReadXmlSerializable(XmlReader)

从 XML 流读取。

RejectChanges()

回滚自加载表或上次 AcceptChanges() 调用表以来对表所做的所有更改。

Reset()

DataTable重置其原始状态。 重置会删除表的所有数据、索引、关系和列。 如果 DataSet 包含 DataTable,则表在重置表后仍将是 DataSet 的一部分。

Select()

获取所有 DataRow 对象的数组。

Select(String, String, DataViewRowState)

获取与筛选器匹配的所有 DataRow 对象的数组,这些对象按与指定状态匹配的排序顺序。

Select(String, String)

获取与筛选条件匹配的所有 DataRow 对象的数组(按指定的排序顺序)。

Select(String)

获取与筛选条件匹配的所有 DataRow 对象的数组。

ToString()

TableName获取 ,DisplayExpression如果存在一个作为串联字符串的字符串,则获取该字符串。

ToString()

返回一个表示当前对象的字符串。

(继承自 Object)
WriteXml(Stream, Boolean)

使用指定的 DataTableXML 写入作为 XML 的Stream当前内容。 若要保存表及其所有后代的数据,请将 writeHierarchy 参数设置为 true

WriteXml(Stream, XmlWriteMode, Boolean)

使用指定的文件将当前数据和架构 DataTable (可选)写入指定的 XmlWriteMode文件。 若要写入架构,请将参数的值 mode 设置为 WriteSchema。 若要保存表及其所有后代的数据,请将 writeHierarchy 参数设置为 true

WriteXml(Stream, XmlWriteMode)

使用指定的文件将当前数据和架构 DataTable (可选)写入指定的 XmlWriteMode文件。 若要写入架构,请将参数的值 mode 设置为 WriteSchema

WriteXml(Stream)

使用指定的 DataTableXML 写入作为 XML 的Stream当前内容。

WriteXml(String, Boolean)

使用指定的文件将作为 XML 的当前内容 DataTable 写入。 若要保存表及其所有后代的数据,请将 writeHierarchy 参数设置为 true

WriteXml(String, XmlWriteMode, Boolean)

为使用指定的文件和 DataTable 写入当前数据和架构(XmlWriteMode可选)。 若要写入架构,请将参数的值 mode 设置为 WriteSchema。 若要保存表及其所有后代的数据,请将 writeHierarchy 参数设置为 true

WriteXml(String, XmlWriteMode)

为使用指定的文件和 DataTable 写入当前数据和架构(XmlWriteMode可选)。 若要写入架构,请将参数的值 mode 设置为 WriteSchema

WriteXml(String)

使用指定的文件将作为 XML 的当前内容 DataTable 写入。

WriteXml(TextWriter, Boolean)

使用指定的 DataTableXML 写入作为 XML 的TextWriter当前内容。 若要保存表及其所有后代的数据,请将 writeHierarchy 参数设置为 true

WriteXml(TextWriter, XmlWriteMode, Boolean)

为使用指定的DataTableTextWriter。(可选)写入当前数据以及架构XmlWriteMode。 若要写入架构,请将参数的值 mode 设置为 WriteSchema。 若要保存表及其所有后代的数据,请将 writeHierarchy 参数设置为 true

WriteXml(TextWriter, XmlWriteMode)

为使用指定的DataTableTextWriter。(可选)写入当前数据以及架构XmlWriteMode。 若要写入架构,请将参数的值 mode 设置为 WriteSchema

WriteXml(TextWriter)

使用指定的 DataTableXML 写入作为 XML 的TextWriter当前内容。

WriteXml(XmlWriter, Boolean)

使用指定的 DataTableXML 写入作为 XML 的XmlWriter当前内容。

WriteXml(XmlWriter, XmlWriteMode, Boolean)

为使用指定的DataTableXmlWriter。(可选)写入当前数据以及架构XmlWriteMode。 若要写入架构,请将参数的值 mode 设置为 WriteSchema。 若要保存表及其所有后代的数据,请将 writeHierarchy 参数设置为 true

WriteXml(XmlWriter, XmlWriteMode)

为使用指定的DataTableXmlWriter。(可选)写入当前数据以及架构XmlWriteMode。 若要写入架构,请将参数的值 mode 设置为 WriteSchema

WriteXml(XmlWriter)

使用指定的 DataTableXML 写入作为 XML 的XmlWriter当前内容。

WriteXmlSchema(Stream, Boolean)

将 XML 架构的 DataTable 当前数据结构写入指定的流。 若要保存表及其所有后代的架构,请将 writeHierarchy 参数设置为 true

WriteXmlSchema(Stream)

将 XML 架构的 DataTable 当前数据结构写入指定的流。

WriteXmlSchema(String, Boolean)

将 XML 架构的 DataTable 当前数据结构写入指定文件。 若要保存表及其所有后代的架构,请将 writeHierarchy 参数设置为 true

WriteXmlSchema(String)

将 XML 架构的 DataTable 当前数据结构写入指定文件。

WriteXmlSchema(TextWriter, Boolean)

使用指定的 DataTableXML 架构写入作为 XML 架构的TextWriter当前数据结构。 若要保存表及其所有后代的架构,请将 writeHierarchy 参数设置为 true

WriteXmlSchema(TextWriter)

使用指定的 DataTableXML 架构写入作为 XML 架构的TextWriter当前数据结构。

WriteXmlSchema(XmlWriter, Boolean)

使用指定的 DataTableXML 架构写入作为 XML 架构的XmlWriter当前数据结构。 若要保存表及其所有后代的架构,请将 writeHierarchy 参数设置为 true

WriteXmlSchema(XmlWriter)

使用指定的 DataTableXML 架构写入作为 XML 架构的XmlWriter当前数据结构。

活动

名称 说明
ColumnChanged

在为指定的DataColumnDataRow值更改后发生。

ColumnChanging

在更改指定值时DataColumnDataRow发生。

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> 对象,其中泛型参数 TDataRow. 此对象可用于 LINQ 表达式或方法查询。

CreateAsyncScope(IServiceProvider)

创建一个可用于解析作用域服务的新 AsyncServiceScope 项。

CreateScope(IServiceProvider)

创建一个可用于解析作用域服务的新 IServiceScope 项。

GetKeyedService(IServiceProvider, Type, Object)

从 .serviceType. 中获取类型的IServiceProvider服务

GetKeyedService<T>(IServiceProvider, Object)

从 .T. 中获取类型的IServiceProvider服务

GetKeyedServices(IServiceProvider, Type, Object)

从中serviceType获取类型IServiceProvider类型的服务的枚举。

GetKeyedServices<T>(IServiceProvider, Object)

从中T获取类型IServiceProvider类型的服务的枚举。

GetRequiredKeyedService(IServiceProvider, Type, Object)

从 .serviceType. 中获取类型的IServiceProvider服务

GetRequiredKeyedService<T>(IServiceProvider, Object)

从 .T. 中获取类型的IServiceProvider服务

GetRequiredService(IServiceProvider, Type)

从 .serviceType. 中获取类型的IServiceProvider服务

GetRequiredService<T>(IServiceProvider)

从 .T. 中获取类型的IServiceProvider服务

GetService<T>(IServiceProvider)

从 .T. 中获取类型的IServiceProvider服务

GetServices(IServiceProvider, Type)

从中serviceType获取类型IServiceProvider类型的服务的枚举。

GetServices<T>(IServiceProvider)

从中T获取类型IServiceProvider类型的服务的枚举。

适用于

线程安全性

此类型对于多线程读取操作是安全的。 必须同步任何写入操作。

另请参阅