Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subset of datatable

Status
Not open for further replies.

bartee

MIS
Mar 20, 2005
147
US
using vs 2005.

I created a dataset in the designer that fills a datatable I'm using to bind to several form controls.

I would like to create a subset of the result set and use this subset as the datasource for a drop down list.

For example, if the original datatable has a column called "company", I would like to create a list of the distinct company rows returned by the datatable.

What's the best way to do this? Can it easily be set-up in the designer?

Thanks in advance.
 
The DataTable has a Select method that you can use to filter the table using an expression.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for the response but I'm not seeing this option.

I have a data adapter that fills the original datatable in my dataset. All done in the designer.

I want to keep this original configuration but, in addition, I want to build another data table off the results of the original. I'm not looking to hit the database with another query -- just want to get the distinct values from a column of the original data table and bind them to a drop down.

Sorry if I'm misunderstanding your original reponse.

Thanks again.
 
What do you mean you don't see that option?
Ex:
Code:
Dim foundrows() As DataRow
foundrows = YourDS.Tables("YourTable").Select("Filter")
ddl.DataSource = foundrows

It does not hit the DB again, it selects the rows, according to the filter your supply, from the existing datatable.

Jim
 
I wasn't seeing the option in the designer.

I put the code sample in the page load and when I replace "YourDS" with the name of the dataset I've created in the designer, I get the following:

"reference to a non-shared member requires an object reference"

Sorry if I'm missing the obvious but am fairly new to .net.

Thanks very much again.
 
You cannot do it in the designer, it needs to be done in code. My code example above should go after you fill your dataset initially in the page load:
Code:
if not ispostback then
   dataadapter.fill(yourds)
   whatever.databind

   .. code from above here ...
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top