Export (0) Print
Expand All
3 out of 3 rated this helpful - Rate this topic

DataTable.Copy Method

Copies both the structure and data for this DataTable.

[Visual Basic]
Public Function Copy() As DataTable
[C#]
public DataTable Copy();
[C++]
public: DataTable* Copy();
[JScript]
public function Copy() : DataTable;

Return Value

A new DataTable with the same structure (table schemas and constraints) and data as this DataTable.

Note   If these classes have been derived, the copy will also be of the same derived classes.

Example

[Visual Basic, C#, C++] The following example uses the Copy method to create a copy of the original DataTable.

[Visual Basic] 
Private Sub CopyDataTable(ByVal myDataTable As DataTable )
    ' Create an object variable for the copy.
    Dim copyDataTable As DataTable
    copyDataTable = myDataTable.Copy()
    ' Insert code to work with the copy.
 End Sub

[C#] 
private void CopyDataTable(DataTable myDataTable){
    // Create an object variable for the copy.
    DataTable copyDataTable;
    copyDataTable = myDataTable.Copy();
    // Insert code to work with the copy.
 }

[C++] 
private:
void CopyDataTable(DataTable* myDataTable){
    // Create an object variable for the copy.
    DataTable* copyDataTable;
    copyDataTable = myDataTable->Copy();
    // Insert code to work with the copy.
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

DataTable Class | DataTable Members | System.Data Namespace | Clone

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.