Filtering a Dataset

ss002d6252

New member
Joined
Jul 3, 2006
Messages
4
Programming Experience
Beginner
I have a dataset (WW1Dataset) with one data table(WW1).(database used in an access database)

I'm trying to filter the dataset e.g a user wants to filter by a chosen surname (SurnameTextBox.text) so the datset is filtered to display only those records wherethe surname column in the dataset matches SurnameTextBox.text.

Any advice on how to do this . Ive tried various ways that I vaguely remember but none work.
 
DataSets don't actually contain any data, so you're not filtering the DataSet. It's the DataTable that contains the data, so you'd want to filter that. The thing is, you can't actually filter a DataTable directly. That's no biggy though, because you wouldn't want to anyway.

If your data is bound to your UI controls then I'd suggest that, if you aren't already, you bind it via a BindingSource. Filtering is then a case of setting the Filter property of that BindingSource, e.g.
VB.NET:
Expand Collapse Copy
Me.BindingSource1.Filter = String.Format("Name LIKE '%{0}%'", Me.nameTextBox)
If you're not using a BindingSource then you can set the RowFilter property of the DataTable's DefaultView the same way. If you access the data in the table you must do so through the DeafaltView, which is done automatically when binding.
 
If youre doing this for search purposes it would be better to have the DB do it (i.e. 1 million records in the db, dont download them all then filter, select only the ones you need instead)

For more info, see the DW2 link in my signature, section "Creating a form to searhc data"
 
Back
Top