DataTable.Copy DataTable.Copy DataTable.Copy DataTable.Copy Method

定義

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

public:
 System::Data::DataTable ^ Copy();
public System.Data.DataTable Copy ();
member this.Copy : unit -> System.Data.DataTable
Public Function Copy () As DataTable

傳回

新的 DataTable,具有與這個 DataTable 相同的結構 (資料表結構描述和條件約束) 和資料。A new DataTable with the same structure (table schemas and constraints) and data as this DataTable.

如果這些類別已形成子類別,則複本也會屬於相同的子類別。If these classes have been derived, the copy will also be of the same derived classes.

Copy() 會建立與原始 DataTable 具有相同結構和資料的新 DataTableCopy() creates a new DataTable with the same structure and data as the original DataTable. 若要將結構複製到新的 DataTable,但是不複製資料,請使用 Clone()To copy the structure to a new DataTable, but not the data, use Clone().

範例

下列範例會使用Copy方法來建立原始DataTable的複本。The following example uses the Copy method to create a copy of the original DataTable. 如果命名空間名稱繼承自父系DataTableDataSet,則不會保留。The namespace name is not retained if it is inherited from a parent DataTable or DataSet.

private void CopyDataTable(DataTable table){
    // Create an object variable for the copy.
    DataTable copyDataTable;
    copyDataTable = table.Copy();

    // Insert code to work with the copy.
 }
Private Sub CopyDataTable(ByVal table As DataTable )
    ' Create an object variable for the copy.
    Dim copyDataTable As DataTable
    copyDataTable = table.Copy()

    ' Insert code to work with the copy.
 End Sub

適用於

另請參閱