DataTable Subset to new DataTable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?anAybXNmdA==?=

    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.Ro wFilter(filterS tring).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
  • Maxwell

    #2
    Re: DataTable Subset to new DataTable

    You may look at the DataTable.Selec t method, which, granted, returns an
    array of DataRow objects, but then you could Add these to a
    dataTable1.Clon e() in a foreach loop.

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

    "jp2msft" <jp2msft@discus sions.microsoft .comwrote in message
    news:DD2372BA-154F-41DB-A879-C3F0F35AFDF3@mi crosoft.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.Ro wFilter(filterS tring).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

    Comment

    Working...