Fastest way to clone a dataset with filter

D

Danny Ni

Hi,

I would like to know the fastest way to clone a dataset with filter inVB.Net
or C#. Say I have a dataset that has one datatable having several data rows.
I want to clone the structure to another dataset but with selection of
datarows.


Please Help!
 
C

Chris Botha

Hope this is the fastest:

Dim theTable as DataTable = theDataSet.Tables(0)
Dim secondTable As DataTable = theTable.Clone()
theTable.DefaultView.RowFilter = "SomeColumn=123" ' If integer
Dim oneRowView As DataRowView
For Each oneRowView In theTable.DefaultView
secondTable.ImportRow(oneRowView.Row)
Next
Dim newDataSet as DataSet = new DataSet
newDataSet.Tables.Add(secondTable)
 
O

Onin Tayson

Hi,

This might be one of the fastest (and shortest code) method to do that.

newDs.Merge(origDs.Tables[0].Select("filterExpression"));

the newDs will be your clone DS that contains the filtered DataRows.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top