Cloning a filtered dataset

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

Daren Hawes

Hi,

Imagine I have a dataset called Surveys with 10 tables. Each table has a
SurveyID. Some SurveyID = 1 Some SurveyID = 2 and so on. .

How can I clone the dataset to make Clone_Surveys but with only the data
rows where SurveyID = 1?

Do I have to create a Dataview for each of the 10 tables? Is there another
way I should know about?

Thanks In Advance
 
Daren,

I'm not sure how much querying you are planning to do beyond this example,
but the assembly I've been working on allows SQL SELECT statements to be
executed against a DataSet. In this case, the query would be something like

SELECT * FROM table1 WHERE surveyid=1
UNION
SELECT * FROM table2 WHERE surveyid=1
UNION
....

The query would return a single DataView with all the matching data combined
in a single DataTable. The DataTable could be added to a new DataSet if
necessary, but I'm not sure why.

You can investigate this further by visiting
http://www.queryadataset.com/query.aspx. Choose the Change Dataset button
and select surveys.xml (I put together a quick example). Then enter the
query:

SELECT * FROM table1 WHERE surveyid=1
UNION
SELECT * FROM table2 WHERE surveyid=1
UNION
SELECT * FROM table3 WHERE surveyid=1
UNION
SELECT * FROM table4 WHERE surveyid=1
UNION
SELECT * FROM table5 WHERE surveyid=1

Of course, you can always upload an example of your DataSet stored to an XML
file and try various queries.

Hope this helps
Adrian Moore
http://www.queryadataset.com
 
Thanks Val. This is what I was looking for too. But I just wanted to know if
there is no way to do it by filtering the dataset itself, and creating a
clone based on the filtered data. As in, using the DataTable or DataView
objects?

Or XSL transformation is the only way to do it? If so, why would that be?

Thanks much,
Sham
 
Hi,

ADO.NET 2.0 allows to select rows into another DataTable, but it is not in a
current version
 
Back
Top