C# .NET - how to filter dataset?

Asked By Craig Vedur on 21-Jun-05 08:01 AM
Hi,
I'm working on an already built app (poorly built).
they do not have collections of objects to bind to a datatable... instead they bind the DataSet directly.  Now they want to build in some sort of filtering to filter the dataset.
now, usually, i build it into the stored procedure and pass in parameters, but, i do not want to modify the SP which does a straight SELECT all type syntax.
is it possible to filter the DataSet?   if so, how?   or will i need to reconstruct the stored procedure?

how to filter dataset?

Asked By NIshant Gaikwad on 21-Jun-05 08:30 AM
u can use a DatasetView for that

Several ways--

Asked By Peter Bromberg on 21-Jun-05 08:56 AM
First, a DataSet is disconnected from the database, so once you have it you no longer have to be concerned about Stored Procs.
First, you have the DataTable Select method:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatatableclassselecttopic.asp
Next, you have the Find method:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatarowcollectionclassfindtopic2.asp
Remember, F1 and Google are your friends.

does the Select method

Asked By Craig Vedur on 21-Jun-05 09:12 AM
work like like a WHERE clause in SQL Server?
for example
ds.tables[0].select("firstname like '%a%' OR lastname like '%b'%")
Woops one more link
Asked By Phillip Jacobs on 21-Jun-05 09:57 AM
I have one more link for you...  This one is a c# application with source code that does exactly what you want.
http://www.codeproject.com/csharp/OazSwitchNetConfig.asp
Filter dataset
Dhana Sekaran replied to Craig Vedur on 25-Jan-08 10:25 AM

Hi,

You can filter dataset values using Select() method of dataset table.

Syntax :

<DataSet>.Tables[0].Select("UserName like 'geo%'");

and so on. Here Tables[0] denotes the first table of the dataset. So you can loop thru the dataset to filter the necessary table data.