Click here to Skip to main content
15,906,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Products list on table in my Dataset...i need to filter products depend on price of products... the price must be within minimum and maximum price .....i tried this
C#
DataSet TempAdsDS=new DataSet();
TempAdsDS = (DataSet)Session["DS"];
rows = TempAdsDS.Tables[0].Select("Price > " + Minimum + " and Price < " + Maximum);


But It will filter products but some wrong products are also available in result.... How can i filter exact correct products in code behind......plz give suggesion for filter exact results from table.....
Posted
Updated 10-May-14 2:08am
v2

Hi,

First check you "Price" column data type it should be numeric (Int,Decimal,Float,Double) otherwise it will not show the proper values.

Apart from that keeping dataset in session/ViewState is not a good idea, so you can write data set in file and store it in some local temp path to uniform your file name you can use Session Id.

[Update]

var tt= TempAdsDS.Tables[0].AsEnumerable().Where( p =&gt; p.Field<int>("Price")>=Minimum && p.Field<int>("Price")<=Maximum)


Thanks,
Suvabrata
 
Share this answer
 
v2
Comments
SnvMohan 9-May-14 7:28am    
Price column is int type only.... But still i can't get correct result....how can i solve this
Suvabrata Roy 9-May-14 8:47am    
If so Then i don't see any error in it.
Or you can try the same using Linq

var tt= TempAdsDS.Tables[0].AsEnumerable().Where( p => p.Field<int>("Price")>Maximum && p.Field<"Price">()
emcp 10-May-14 9:12am    
And the types of Minimum and Maximum?
Suvabrata Roy 13-May-14 0:04am    
In this case it should be numeric.

Please refer to update section of my answer for proper LINQ.
SnvMohan 14-May-14 4:55am    
Now its working fine... Thank you....
Datatable dt1=new Datatable();
dt1=TempAdsDS.Tables[0];
string filter = ""Price > " + Minimum + " and Price < " + Maximum";

DataView view = new DataView(dt1);
view.RowFilter = filter;
dt1 = view.ToTable();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900