471,330 Members | 1,178 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

DataTable Subset to new DataTable

How would I copy all data from my DataSet that meets a filtering condition to
a new DataTable?

Is this what I want?

DataTable table = new DataTable();
table = DataSet1.Table[0].DefaultView.RowFilter(filterString).Copy();

This still copies over all of the data, but adds a filter. Right?

This also creates a Default View on the first DataTable in my DataSet, which
I do not want.

After copying the filtered data to a new DataTable, I need to further filter
the DataTable about 3 more times and combine it's data with another
DataTable's data and filter that, too.

Any pointers or suggestions would be appreciated.

I wasn't able to locate this information in the Hitchhiker's Guide to Visual
Studio and SQL Server (#7).

Regards,
Joe
Jul 31 '08 #1
1 4483
You may look at the DataTable.Select method, which, granted, returns an
array of DataRow objects, but then you could Add these to a
dataTable1.Clone() in a foreach loop.

Not an all-in-one solution, but you might give it a go.

"jp2msft" <jp*****@discussions.microsoft.comwrote in message
news:DD**********************************@microsof t.com...
How would I copy all data from my DataSet that meets a filtering condition
to
a new DataTable?

Is this what I want?

DataTable table = new DataTable();
table = DataSet1.Table[0].DefaultView.RowFilter(filterString).Copy();

This still copies over all of the data, but adds a filter. Right?

This also creates a Default View on the first DataTable in my DataSet,
which
I do not want.

After copying the filtered data to a new DataTable, I need to further
filter
the DataTable about 3 more times and combine it's data with another
DataTable's data and filter that, too.

Any pointers or suggestions would be appreciated.

I wasn't able to locate this information in the Hitchhiker's Guide to
Visual
Studio and SQL Server (#7).

Regards,
Joe

Jul 31 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by jensen bredal | last post: by
6 posts views Thread by Pete Wittig | last post: by
2 posts views Thread by =?Utf-8?B?Sm9iIExvdA==?= | last post: by
1 post views Thread by byrd48 | last post: by
2 posts views Thread by ciccone1978 | last post: by
9 posts views Thread by Nathan Sokalski | last post: by
5 posts views Thread by jehugaleahsa | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.