Cloning Datasets but also filtering

  • Thread starter Thread starter Daren Hawes
  • Start date Start date
D

Daren Hawes

Hi,

I have 2 Datasets with 20 tables.

Ones called Surveys and the other SingleSurveys.

Surveys contains ALL survey data (IE SurveyID = 1,2,3,4,5......). All
tables have related ID field (IE SurveyID on each table)

I need to copy over to SingleSurveys only one survey data (IE SurveyID = 12)

The SingleSurvey should contain all the same tables, but filtered fields by
the SurveyID.

Is there a fast way to do this? Dataviews?

I have investigated some components but the seem to put all the data in 1
table. I need the same structure just data pertaining to a certain
surveyID?

Thanks Daren
 
Daren,

This is a quickly in this message made sample that would do the job in my
idea. However watch typos or what so ever.

\\\
DataTable dt = MyFirstDatatable.Tables("Whatever");
DataView dv = new DataView(dt);
dv.RowFilter = "MyCriteria = Whatever";
DataTable dtnew = dt.Clone();
foreach (DataRowView dvr in dv)
dtnew.ImportRow(dvr.Row);
dt.Clear();
MyOtherDataset.Tables.Add(dtnew);
///

I hope this helps,

Cor
 
Daren Hawes said:
The SingleSurvey should contain all the same tables, but filtered
fields by the SurveyID.

Is there a fast way to do this? Dataviews?

A dataview will do it without copying it.
 
Daren,

You might be interested in the assembly I've been working on at
http://www.queryadataset.com. It lets you perform complex SQL SELECT
statements including UNION, JOINS, GROUP BY, HAVING, ORDER BY, sub-queries,
etc against the tables in a dataset. It also supports SELECT INTO. In your
case you could issue the following query against the Surveys DataSet.

SELECT * INTO [table name] FROM [table name] WHERE SurveyID=12

The table name in the INTO clause can be the same name as the FROM clause.
INTO simply sets the name of the DataTable being returned in the DataView.
This table can be added to your SingleSurveys DataSet. This is a great way
to create a filtered clone of a DataSet.

I know I've offered you help before and you might have visited the web-site
previously. However, its been updated and there is now a demo download you
can try.

Hope this helps
Adrian Moore
http://www.queryadataset.com
 
Back
Top