Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Can somebody please point out why the following is not a valid method of checking if a number falls within a particular range?
products = products.Where(string.Format("price >= {0} and price is <= {1}", decimal.Parse(Request.Form["minPrice"]), decimal.Parse(Request.Form["maxPrice"])));
I am getting a syntax error exception which is a System.Linq.Dynamic.ParseException type if that helps.
Simon
What is the is in query? ( and price is <= {1} )
Try this :
products = products.Where(string.Format("price >= {0} && price <= {1}",decimal.Parse(Request.Form["minPrice"]),decimal.Parse(Request.Form["maxPrice"])));
What is products? you can paste the code how do you get it and how you declare it?
Hope that help.
Cheers
Thanks for pointing out my now very obvious school boy error, a case of not being able to see the wood for the trees! The issue was of course the "is" that had been added somehow in error :(
Just FYI, you can use the Where method without string.Format as it already parses the condition for parameters and replaces them, as in:
products = products.Where("price >= @0 && price <= @1", decimal.Parse(Request.Form["minPrice"]), decimal.Parse(Request.Form["maxPrice"])));
Good to know, thanks Douglas.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Where clause exceptions when comparing numerics
Can somebody please point out why the following is not a valid method of checking if a number falls within a particular range?
I am getting a syntax error exception which is a System.Linq.Dynamic.ParseException type if that helps.
Simon
What is the is in query? ( and price is <= {1} )
Try this :
What is products? you can paste the code how do you get it and how you declare it?
Hope that help.
Cheers
Thanks for pointing out my now very obvious school boy error, a case of not being able to see the wood for the trees! The issue was of course the "is" that had been added somehow in error :(
Just FYI, you can use the Where method without string.Format as it already parses the condition for parameters and replaces them, as in:
Good to know, thanks Douglas.
is working on a reply...