VB.Net - Datatable Sample - Copy a DataTable

1
2
3
4
5
6
'
' This is a copy of the same table.
' Kind of like creates a second pointer into the same table
'
dim ds as dataset = si_db.ds_get("Select * from Customers")
dim dt as datatable = ds.tables(0).copy()

The problem with is is the changes made to the copy (such as a filter) show up on the original table as well. Sometimes this is confusing.

1
2
3
4
5
6
7
8
' This makes a copy of a table that can be independantly manipulated.
'
Dim dt As DataTable = ds.Tables(0)
Dim dtCopy As DataTable = dt.Clone
For Each aRow As DataRow In dt.Select("Mark=1")
'dtCopy.insertRow(aRow) ' 12/31/2008 - hmm why doesn't this work
dtCopy.Rows.Add(aRow)
Next