DataTable 類別

定義

表示記憶體中資料的一個資料表。Represents one table of in-memory data.

public ref class DataTable : System::ComponentModel::MarshalByValueComponent, System::ComponentModel::IListSource, System::ComponentModel::ISupportInitializeNotification, System::Runtime::Serialization::ISerializable, System::Xml::Serialization::IXmlSerializable
[System.Serializable]
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 ISupportInitializeNotification
    interface ISerializable
    interface IXmlSerializable
    interface ISupportInitialize
Public Class DataTable
Inherits MarshalByValueComponent
Implements IListSource, ISerializable, ISupportInitializeNotification, IXmlSerializable
繼承
衍生
屬性
實作

範例

下列範例會建立兩DataTable個物件和DataRelation一個物件,並將新DataSet的物件加入至。The following example creates two DataTable objects and one DataRelation object, and adds the new objects to a DataSet. 然後,資料表會顯示在DataGridView控制項中。The tables are then displayed in a DataGridView control.

   // 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:This sample demonstrates how to create a DataTable manually with specific schema definitions:

  • 建立多個 Datatable 並定義初始資料行。Create multiple DataTables and define the initial columns.

  • 建立資料表條件約束。Create the table constraints.

  • 插入值並顯示資料表。Insert the values and display the tables.

  • 建立運算式資料行並顯示資料表。Create the expression columns and display the tables.

C#使用此程式碼範例 Visual Basic 專案,可以在開發人員程式碼範例中找到。C# and Visual Basic projects with this code sample can be found on Developer Code Samples.

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 程式庫中的中央物件。The DataTable is a central object in the ADO.NET library. 其他使用的DataTable物件DataSet包括和DataViewOther objects that use the DataTable include the DataSet and the DataView.

存取DataTable物件時,請注意,它們會有條件地區分大小寫。When accessing DataTable objects, note that they are conditionally case sensitive. 例如,如果一個DataTable名稱為 "mydatatable",另一個名為 "mydatatable",則用來搜尋其中一個資料表的字串會被視為區分大小寫。For example, if one DataTable is named "mydatatable" and another is named "Mydatatable", a string used to search for one of the tables is regarded as case sensitive. 不過,如果 "mydatatable" 存在,而且 "Mydatatable" 不是,則會將搜尋字串視為不區分大小寫。However, if "mydatatable" exists and "Mydatatable" does not, the search string is regarded as case insensitive. 可以包含兩個DataTable具有相同TableName屬性值但屬性值不同Namespace的物件。 DataSetA DataSet can contain two DataTable objects that have the same TableName property value but different Namespace property values. 如需使用DataTable物件的詳細資訊,請參閱建立 DataTableFor more information about working with DataTable objects, see Creating a DataTable.

如果您要DataTable以程式設計方式建立,則必須先將物件加入DataColumnDataColumnCollection (透過Columns屬性存取),以定義其架構。If you are creating a DataTable programmatically, you must first define its schema by adding DataColumn objects to the DataColumnCollection (accessed through the Columns property). 如需有關加入DataColumn物件的詳細資訊,請參閱將資料行加入至 DataTableFor more information about adding DataColumn objects, see Adding Columns to a DataTable.

若要將資料列DataTable加入至,您必須先NewRow使用方法來傳回新DataRow的物件。To add rows to a DataTable, you must first use the NewRow method to return a new DataRow object. 方法會傳回具有架構DataTable的資料列,因為它是由資料表的DataColumnCollection所定義。 NewRowThe NewRow method returns a row with the schema of the DataTable, as it is defined by the table's DataColumnCollection. DataTable可以儲存的最大資料列數目是16777216。The maximum number of rows that a DataTable can store is 16,777,216. 如需詳細資訊,請參閱將資料加入至 DataTableFor more information, see Adding Data to a DataTable.

也包含Constraint物件的集合,可用於確保資料的完整性。 DataTableThe DataTable also contains a collection of Constraint objects that can be used to ensure the integrity of the data. 如需詳細資訊,請參閱DataTable 條件約束For more information, see DataTable Constraints.

有許多DataTable事件可以用來判斷對資料表進行變更的時間。There are many DataTable events that can be used to determine when changes are made to a table. 其中包括 RowChangedRowChangingRowDeletingRowDeletedThese include RowChanged, RowChanging, RowDeleting, and RowDeleted. 如需可搭配使用DataTable之事件的詳細資訊,請參閱處理 DataTable 事件For more information about the events that can be used with a DataTable, see Handling DataTable Events.

建立的實例DataTable時,部分的讀取/寫入屬性會設定為初始值。When an instance of DataTable is created, some of the read/write properties are set to initial values. 如需這些值的清單,請參閱DataTable.DataTable函式主題。For a list of these values, see the DataTable.DataTable constructor topic.

注意

和物件繼承自MarshalByValueComponent,而且支援 .NET Framework 遠端ISerializable處理的介面。 DataTable DataSetThe DataSet and DataTable objects inherit from MarshalByValueComponent, and support the ISerializable interface for .NET Framework remoting. 這些是唯一可用於 .NET Framework 遠端處理的 ADO.NET 物件。These are the only ADO.NET objects that you can use for .NET Framework remoting.

建構函式

DataTable()

不使用引數來初始化 DataTable 類別的新執行個體。Initializes a new instance of the DataTable class with no arguments.

DataTable(SerializationInfo, StreamingContext)

使用 DataTableSerializationInfo,初始化 StreamingContext 類別的新執行個體。Initializes a new instance of the DataTable class with the SerializationInfo and the StreamingContext.

DataTable(String)

使用指定的資料表名稱,初始化 DataTable 類別的新執行個體。Initializes a new instance of the DataTable class with the specified table name.

DataTable(String, String)

使用指定的資料表名稱和命名空間,初始化 DataTable 類別的新執行個體。Initializes a new instance of the DataTable class using the specified table name and namespace.

欄位

fInitInProgress

檢查初始化是否仍在進行中。Checks whether initialization is in progress. 初始化發生於執行階段。The initialization occurs at run time.

屬性

CaseSensitive

指示字串比較在資料表中是否區分大小寫。Indicates whether string comparisons within the table are case-sensitive.

ChildRelations

為這個 DataTable 取得子關聯的集合。Gets the collection of child relations for this DataTable.

Columns

取得屬於這個資料表的資料行集合。Gets the collection of columns that belong to this table.

Constraints

取得這個資料表所維護的條件約束 (Constraint) 集合。Gets the collection of constraints maintained by this table.

Container

取得元件的容器。Gets the container for the component.

(繼承來源 MarshalByValueComponent)
DataSet

取得這個資料表所屬的 DataSetGets the DataSet to which this table belongs.

DefaultView

取得可能含有已篩選檢視表或游標位置的資料表自訂檢視表。Gets a customized view of the table that may include a filtered view, or a cursor position.

DesignMode

取得值,表示元件目前是否處於設計模式。Gets a value indicating whether the component is currently in design mode.

(繼承來源 MarshalByValueComponent)
DisplayExpression

取得或設定會傳回用來在使用者介面中表示這個資料表之值的運算式。Gets or sets the expression that returns a value used to represent this table in the user interface. DisplayExpression 屬性可讓您將這個資料表的名稱顯示在使用者介面中。The DisplayExpression property lets you display the name of this table in a user interface.

Events

取得附加在這個元件上的事件處理常式清單。Gets the list of event handlers that are attached to this component.

(繼承來源 MarshalByValueComponent)
ExtendedProperties

取得自訂使用者資訊的集合。Gets the collection of customized user information.

HasErrors

取得值,指出資料表所屬 DataSet 的任何資料表中的任何資料列是否存在錯誤。Gets a value indicating whether there are errors in any of the rows in any of the tables of the DataSet to which the table belongs.

IsInitialized

取得值,指出 DataTable 是否已初始化。Gets a value that indicates whether the DataTable is initialized.

Locale

取得或設定用來在資料表中比較字串的地區設定 (Locale) 資訊。Gets or sets the locale information used to compare strings within the table.

MinimumCapacity

取得或設定這個資料表的初始開始大小。Gets or sets the initial starting size for this table.

Namespace

為在 DataTable 中所儲存資料的 XML 表示取得或設定命名空間。Gets or sets the namespace for the XML representation of the data stored in the DataTable.

ParentRelations

為這個 DataTable 取得父關聯的集合。Gets the collection of parent relations for this DataTable.

Prefix

為在 DataTable 中所儲存資料的 XML 表示取得或設定命名空間。Gets or sets the namespace for the XML representation of the data stored in the DataTable.

PrimaryKey

取得或設定資料行的陣列,這些資料行是做為資料表 (Data Table) 之主索引鍵。Gets or sets an array of columns that function as primary keys for the data table.

RemotingFormat

取得或設定序列化格式。Gets or sets the serialization format.

Rows

取得屬於這個資料表的資料列集合。Gets the collection of rows that belong to this table.

Site

取得或設定 ISiteDataTableGets or sets an ISite for the DataTable.

TableName

取得或設定 DataTable 的名稱。Gets or sets the name of the DataTable.

方法

AcceptChanges()

認可自前一次呼叫 AcceptChanges() 以來對這個資料表所做的所有變更。Commits all the changes made to this table since the last time AcceptChanges() was called.

BeginInit()

開始對表單或另一個元件所使用的 DataTable 進行初始化作業。Begins the initialization of a DataTable that is used on a form or used by another component. 初始化發生於執行階段。The initialization occurs at run time.

BeginLoadData()

載入資料時關閉告知、索引維護和條件約束。Turns off notifications, index maintenance, and constraints while loading data.

Clear()

清除所有資料的 DataTableClears the DataTable of all data.

Clone()

複製 (Clone) DataTable 的結構,包括所有 DataTable 結構描述和條件約束。Clones the structure of the DataTable, including all DataTable schemas and constraints.

Compute(String, String)

計算在傳遞篩選準則的目前資料列上的指定運算式。Computes the given expression on the current rows that pass the filter criteria.

Copy()

複製這個 DataTable 的結構和資料。Copies both the structure and data for this DataTable.

CreateDataReader()

傳回對應於這個 DataTableReader 之中資料的 DataTableReturns a DataTableReader corresponding to the data within this DataTable.

CreateInstance()

建立 DataTable 的新執行個體。Creates a new instance of DataTable.

Dispose()

釋放 MarshalByValueComponent 所使用的所有資源。Releases all resources used by the MarshalByValueComponent.

(繼承來源 MarshalByValueComponent)
Dispose(Boolean)

釋放 MarshalByValueComponent 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources.

(繼承來源 MarshalByValueComponent)
EndInit()

結束對表單或另一個元件所使用的 DataTable 進行初始化作業。Ends the initialization of a DataTable that is used on a form or used by another component. 初始化發生於執行階段。The initialization occurs at run time.

EndLoadData()

載入資料後開啟告知、索引維護和條件約束。Turns on notifications, index maintenance, and constraints after loading data.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetChanges()

取得 DataTable (包含從載入它或前一次呼叫 AcceptChanges() 以來所做的所有變更) 的複本。Gets a copy of the DataTable that contains all changes made to it since it was loaded or AcceptChanges() was last called.

GetChanges(DataRowState)

取得 DataTable (包含從前一次載入它或呼叫 AcceptChanges() 以來所做的所有變更) 的複本 (由 DataRowState 篩選)。Gets a copy of the DataTable containing all changes made to it since it was last loaded, or since AcceptChanges() was called, filtered by DataRowState.

GetDataTableSchema(XmlSchemaSet)

這個方法會傳回 XmlSchemaSet 執行個體,此執行個體包含描述 Web 服務之 DataTable 的 Web 服務描述語言 (WSDL)。This method returns an XmlSchemaSet instance containing the Web Services Description Language (WSDL) that describes the DataTable for Web Services.

GetErrors()

取得包含錯誤之 DataRow 物件的陣列。Gets an array of DataRow objects that contain errors.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)

以序列化 DataTable 所需的資料,填入序列化資訊物件。Populates a serialization information object with the data needed to serialize the DataTable.

GetRowType()

取得資料列型別。Gets the row type.

GetSchema()

如需這個成員的說明,請參閱 GetSchema()For a description of this member, see GetSchema().

GetService(Type)

取得 IServiceProvider 的實作器。Gets the implementer of the IServiceProvider.

(繼承來源 MarshalByValueComponent)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
ImportRow(DataRow)

DataRow 複製至 DataTable,保留任何屬性設定,以及原始值和目前值。Copies a DataRow into a DataTable, preserving any property settings, as well as original and current values.

Load(IDataReader)

使用所提供的 DataTable,用資料來源的值填滿 IDataReaderFills a DataTable with values from a data source using the supplied IDataReader. 如果 DataTable 已經包含資料列,從資料來源傳入的資料會與現有的資料列合併。If the DataTable already contains rows, the incoming data from the data source is merged with the existing rows.

Load(IDataReader, LoadOption)

使用所提供的 DataTable,用資料來源的值填滿 IDataReaderFills a DataTable with values from a data source using the supplied IDataReader. 如果 DataTable 已經包含資料列,從資料來源傳入的資料會根據 loadOption 參數的值,與現有的資料列合併。If the DataTable already contains rows, the incoming data from the data source is merged with the existing rows according to the value of the loadOption parameter.

Load(IDataReader, LoadOption, FillErrorEventHandler)

使用所提供的 DataTable,以資料來源的值填滿 IDataReader,使用錯誤處理委派。Fills a DataTable with values from a data source using the supplied IDataReader using an error-handling delegate.

LoadDataRow(Object[], Boolean)

尋找並更新特定資料列。Finds and updates a specific row. 如果找不到符合的資料列,則使用指定值來建立新的資料列。If no matching row is found, a new row is created using the given values.

LoadDataRow(Object[], LoadOption)

尋找並更新特定資料列。Finds and updates a specific row. 如果找不到符合的資料列,則使用指定值來建立新的資料列。If no matching row is found, a new row is created using the given values.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
Merge(DataTable)

將指定的 DataTable 與目前的 DataTable 合併。Merge the specified DataTable with the current DataTable.

Merge(DataTable, Boolean)

合併指定的 DataTable 與目前的 DataTable,指出是否保留目前 DataTable 中的變更。Merge the specified DataTable with the current DataTable, indicating whether to preserve changes in the current DataTable.

Merge(DataTable, Boolean, MissingSchemaAction)

合併指定的 DataTable 與目前的 DataTable,指出是否保留變更,以及如何處理目前在 DataTable 中缺少的結構描述。Merge the specified DataTable with the current DataTable, indicating whether to preserve changes and how to handle missing schema in the current DataTable.

NewRow()

使用與資料表相同的結構描述來建立新的 DataRowCreates a new DataRow with the same schema as the table.

NewRowArray(Int32)

傳回 DataRow 的陣列。Returns an array of DataRow.

NewRowFromBuilder(DataRowBuilder)

從現有的資料列建立新的資料列。Creates a new row from an existing row.

OnColumnChanged(DataColumnChangeEventArgs)

引發 ColumnChanged 事件。Raises the ColumnChanged event.

OnColumnChanging(DataColumnChangeEventArgs)

引發 ColumnChanging 事件。Raises the ColumnChanging event.

OnPropertyChanging(PropertyChangedEventArgs)

引發 PropertyChanged 事件。Raises the PropertyChanged event.

OnRemoveColumn(DataColumn)

DataTable 通知 DataColumn 正在移除。Notifies the DataTable that a DataColumn is being removed.

OnRowChanged(DataRowChangeEventArgs)

引發 RowChanged 事件。Raises the RowChanged event.

OnRowChanging(DataRowChangeEventArgs)

引發 RowChanging 事件。Raises the RowChanging event.

OnRowDeleted(DataRowChangeEventArgs)

引發 RowDeleted 事件。Raises the RowDeleted event.

OnRowDeleting(DataRowChangeEventArgs)

引發 RowDeleting 事件。Raises the RowDeleting event.

OnTableCleared(DataTableClearEventArgs)

引發 TableCleared 事件。Raises the TableCleared event.

OnTableClearing(DataTableClearEventArgs)

引發 TableClearing 事件。Raises the TableClearing event.

OnTableNewRow(DataTableNewRowEventArgs)

引發 TableNewRow 事件。Raises the TableNewRow event.

ReadXml(Stream)

使用指定的 DataTable,將 XML 結構描述和資料讀入 StreamReads XML schema and data into the DataTable using the specified Stream.

ReadXml(String)

將 XML 結構描述和資料從指定的檔案讀入 DataTableReads XML schema and data into the DataTable from the specified file.

ReadXml(TextReader)

使用指定的 DataTable,將 XML 結構描述和資料讀入 TextReaderReads XML schema and data into the DataTable using the specified TextReader.

ReadXml(XmlReader)

使用指定的 DataTable,將 XML 結構描述和資料讀入 XmlReaderReads XML Schema and Data into the DataTable using the specified XmlReader.

ReadXmlSchema(Stream)

使用指定的資料流,將 XML 結構描述讀入 DataTableReads an XML schema into the DataTable using the specified stream.

ReadXmlSchema(String)

從指定的檔案,將 XML 結構描述讀入 DataTableReads an XML schema into the DataTable from the specified file.

ReadXmlSchema(TextReader)

使用指定的 DataTable,將 XML 結構描述讀入 TextReaderReads an XML schema into the DataTable using the specified TextReader.

ReadXmlSchema(XmlReader)

使用指定的 DataTable,將 XML 結構描述讀入 XmlReaderReads an XML schema into the DataTable using the specified XmlReader.

ReadXmlSerializable(XmlReader)

從 XML 資料流讀取。Reads from an XML stream.

RejectChanges()

復原從資料表載入以來,或前一次呼叫 AcceptChanges() 以來,對該資料表所做的所有變更。Rolls back all changes that have been made to the table since it was loaded, or the last time AcceptChanges() was called.

Reset()

重設 DataTable 為它的原始狀態。Resets the DataTable to its original state. 重設會移除資料表的所有資料、索引、關聯和資料行。Reset removes all data, indexes, relations, and columns of the table. 如果資料集包含 DataTable,則重設資料表之後,資料表仍將是資料集的一部分。If a DataSet includes a DataTable, the table will still be part of the DataSet after the table is reset.

Select()

取得所有 DataRow 物件的陣列。Gets an array of all DataRow objects.

Select(String)

取得所有符合篩選準則之 DataRow 物件的陣列。Gets an array of all DataRow objects that match the filter criteria.

Select(String, String)

取得按照指定排序順序符合篩選條件的所有 DataRow 物件之陣列。Gets an array of all DataRow objects that match the filter criteria, in the specified sort order.

Select(String, String, DataViewRowState)

取得符合篩選條件 (按照排序順序,並符合指定狀態) 的所有 DataRow 物件之陣列。Gets an array of all DataRow objects that match the filter in the order of the sort that match the specified state.

ToString()

如果存在串連的字串,則取得 TableNameDisplayExpressionGets the TableName and DisplayExpression, if there is one as a concatenated string.

WriteXml(Stream)

使用指定的 Stream,將 DataTable 目前的內容寫入為 XML。Writes the current contents of the DataTable as XML using the specified Stream.

WriteXml(Stream, Boolean)

使用指定的 Stream,將 DataTable 目前的內容寫入為 XML。Writes the current contents of the DataTable as XML using the specified Stream. 若要儲存資料表及其所有子系的資料,請將 writeHierarchy 參數設定為 trueTo save the data for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXml(Stream, XmlWriteMode)

使用指定的 DataTable,寫入 XmlWriteMode 的目前資料 (並選擇性寫入結構描述) 至指定的檔案。Writes the current data, and optionally the schema, for the DataTable to the specified file using the specified XmlWriteMode. 若要寫入結構描述,請設定 mode 參數的值為 WriteSchemaTo write the schema, set the value for the mode parameter to WriteSchema.

WriteXml(Stream, XmlWriteMode, Boolean)

使用指定的 DataTable,寫入 XmlWriteMode 的目前資料 (並選擇性寫入結構描述) 至指定的檔案。Writes the current data, and optionally the schema, for the DataTable to the specified file using the specified XmlWriteMode. 若要寫入結構描述,請設定 mode 參數的值為 WriteSchemaTo write the schema, set the value for the mode parameter to WriteSchema. 若要儲存資料表及其所有子系的資料,請將 writeHierarchy 參數設定為 trueTo save the data for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXml(String)

使用指定的檔案,將 DataTable 目前的內容寫成 XML。Writes the current contents of the DataTable as XML using the specified file.

WriteXml(String, Boolean)

使用指定的檔案,將 DataTable 目前的內容寫成 XML。Writes the current contents of the DataTable as XML using the specified file. 若要儲存資料表及其所有子系的資料,請將 writeHierarchy 參數設定為 trueTo save the data for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXml(String, XmlWriteMode)

使用指定的檔案和 DataTable,寫入 XmlWriteMode 的目前資料,並選擇性寫入結構描述。Writes the current data, and optionally the schema, for the DataTable using the specified file and XmlWriteMode. 若要寫入結構描述,請設定 mode 參數的值為 WriteSchemaTo write the schema, set the value for the mode parameter to WriteSchema.

WriteXml(String, XmlWriteMode, Boolean)

使用指定的檔案和 DataTable,寫入 XmlWriteMode 的目前資料,並選擇性寫入結構描述。Writes the current data, and optionally the schema, for the DataTable using the specified file and XmlWriteMode. 若要寫入結構描述,請設定 mode 參數的值為 WriteSchemaTo write the schema, set the value for the mode parameter to WriteSchema. 若要儲存資料表及其所有子系的資料,請將 writeHierarchy 參數設定為 trueTo save the data for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXml(TextWriter)

使用指定的 TextWriter,將 DataTable 目前的內容寫入為 XML。Writes the current contents of the DataTable as XML using the specified TextWriter.

WriteXml(TextWriter, Boolean)

使用指定的 TextWriter,將 DataTable 目前的內容寫入為 XML。Writes the current contents of the DataTable as XML using the specified TextWriter. 若要儲存資料表及其所有子系的資料,請將 writeHierarchy 參數設定為 trueTo save the data for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXml(TextWriter, XmlWriteMode)

使用指定的 DataTableTextWriter,寫入 XmlWriteMode 的目前資料,並選擇性寫入結構描述。Writes the current data, and optionally the schema, for the DataTable using the specified TextWriter and XmlWriteMode. 若要寫入結構描述,請設定 mode 參數的值為 WriteSchemaTo write the schema, set the value for the mode parameter to WriteSchema.

WriteXml(TextWriter, XmlWriteMode, Boolean)

使用指定的 DataTableTextWriter,寫入 XmlWriteMode 的目前資料,並選擇性寫入結構描述。Writes the current data, and optionally the schema, for the DataTable using the specified TextWriter and XmlWriteMode. 若要寫入結構描述,請設定 mode 參數的值為 WriteSchemaTo write the schema, set the value for the mode parameter to WriteSchema. 若要儲存資料表及其所有子系的資料,請將 writeHierarchy 參數設定為 trueTo save the data for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXml(XmlWriter)

使用指定的 XmlWriter,將 DataTable 目前的內容寫入為 XML。Writes the current contents of the DataTable as XML using the specified XmlWriter.

WriteXml(XmlWriter, Boolean)

使用指定的 XmlWriter,將 DataTable 目前的內容寫入為 XML。Writes the current contents of the DataTable as XML using the specified XmlWriter.

WriteXml(XmlWriter, XmlWriteMode)

使用指定的 DataTableXmlWriter,寫入 XmlWriteMode 的目前資料,並選擇性寫入結構描述。Writes the current data, and optionally the schema, for the DataTable using the specified XmlWriter and XmlWriteMode. 若要寫入結構描述,請設定 mode 參數的值為 WriteSchemaTo write the schema, set the value for the mode parameter to WriteSchema.

WriteXml(XmlWriter, XmlWriteMode, Boolean)

使用指定的 DataTableXmlWriter,寫入 XmlWriteMode 的目前資料,並選擇性寫入結構描述。Writes the current data, and optionally the schema, for the DataTable using the specified XmlWriter and XmlWriteMode. 若要寫入結構描述,請設定 mode 參數的值為 WriteSchemaTo write the schema, set the value for the mode parameter to WriteSchema. 若要儲存資料表及其所有子系的資料,請將 writeHierarchy 參數設定為 trueTo save the data for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXmlSchema(Stream)

DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的資料流。Writes the current data structure of the DataTable as an XML schema to the specified stream.

WriteXmlSchema(Stream, Boolean)

DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的資料流。Writes the current data structure of the DataTable as an XML schema to the specified stream. 若要儲存資料表及其所有子代的結構描述,請將 writeHierarchy 參數設定為 trueTo save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXmlSchema(String)

DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的檔案。Writes the current data structure of the DataTable as an XML schema to the specified file.

WriteXmlSchema(String, Boolean)

DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的檔案。Writes the current data structure of the DataTable as an XML schema to the specified file. 若要儲存資料表及其所有子代的結構描述,請將 writeHierarchy 參數設定為 trueTo save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXmlSchema(TextWriter)

使用指定的 DataTable,將 TextWriter 目前的資料結構撰寫成 XML 結構描述。Writes the current data structure of the DataTable as an XML schema using the specified TextWriter.

WriteXmlSchema(TextWriter, Boolean)

使用指定的 DataTable,將 TextWriter 目前的資料結構撰寫成 XML 結構描述。Writes the current data structure of the DataTable as an XML schema using the specified TextWriter. 若要儲存資料表及其所有子代的結構描述,請將 writeHierarchy 參數設定為 trueTo save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

WriteXmlSchema(XmlWriter)

使用指定的 DataTable,將 XmlWriter 目前的資料結構撰寫成 XML 結構描述。Writes the current data structure of the DataTable as an XML schema using the specified XmlWriter.

WriteXmlSchema(XmlWriter, Boolean)

使用指定的 DataTable,將 XmlWriter 目前的資料結構撰寫成 XML 結構描述。Writes the current data structure of the DataTable as an XML schema using the specified XmlWriter. 若要儲存資料表及其所有子代的結構描述,請將 writeHierarchy 參數設定為 trueTo save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

事件

ColumnChanged

發生在值已經為 DataColumn 中指定的 DataRow 變更之後。Occurs after a value has been changed for the specified DataColumn in a DataRow.

ColumnChanging

發生在值正在為 DataColumn 中指定的 DataRow 變更之後。Occurs when a value is being changed for the specified DataColumn in a DataRow.

Disposed

加入事件處理常式來接聽 (Listen) 元件上的 Disposed 事件。Adds an event handler to listen to the Disposed event on the component.

(繼承來源 MarshalByValueComponent)
Initialized

發生於 DataTable 初始化之後。Occurs after the DataTable is initialized.

RowChanged

成功變更 DataRow 後發生。Occurs after a DataRow has been changed successfully.

RowChanging

發生在 DataRow 正在變更時。Occurs when a DataRow is changing.

RowDeleted

發生在資料表中的資料列已經刪除之後。Occurs after a row in the table has been deleted.

RowDeleting

發生在資料表中的資料列將要刪除之前。Occurs before a row in the table is about to be deleted.

TableCleared

發生在清除 DataTable 之後。Occurs after a DataTable is cleared.

TableClearing

發生於清除 DataTable 時。Occurs when a DataTable is cleared.

TableNewRow

發生在插入新的 DataRow 時。Occurs when a new DataRow is inserted.

明確介面實作

IListSource.ContainsListCollection

如需這個成員的說明,請參閱 ContainsListCollectionFor a description of this member, see ContainsListCollection.

IListSource.GetList()

如需這個成員的說明,請參閱 GetList()For a description of this member, see GetList().

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

以序列化 DataTable 所需的資料,填入序列化資訊物件。Populates a serialization information object with the data needed to serialize the DataTable.

IXmlSerializable.GetSchema()

如需這個成員的說明,請參閱 GetSchema()For a description of this member, see GetSchema().

IXmlSerializable.ReadXml(XmlReader)

如需這個成員的說明,請參閱 ReadXml(XmlReader)For a description of this member, see ReadXml(XmlReader).

IXmlSerializable.WriteXml(XmlWriter)

如需這個成員的說明,請參閱 WriteXml(XmlWriter)For a description of this member, see WriteXml(XmlWriter).

擴充方法

AsDataView(DataTable)

建立並傳回已啟用 LINQ 的 DataView 物件。Creates and returns a LINQ-enabled DataView object.

AsEnumerable(DataTable)

傳回 IEnumerable<T> 物件,其中泛型參數 TDataRowReturns an IEnumerable<T> object, where the generic parameter T is DataRow. 這個物件可以在 LINQLINQ 運算式或方法查詢中使用。This object can be used in a LINQLINQ expression or method query.

適用於

執行緒安全性

這種類型對於多執行緒讀取作業而言是安全的。This type is safe for multithreaded read operations. 您必須同步處理任何寫入作業。You must synchronize any write operations.

另請參閱