0

I have a field in a dataset and im querying using Linq my code is

 var countriesQry = from a in countTbl.AsEnumerable()
                               where a["CountryId"].ToString().Contains(countryId)
                               orderby a["CountryId"]

my problem is that in the "CountryId" field there can be a countryid of 1,22,13 (its a varchar field) so something can be a few countries. as you can guess its returning 1 and 13 if the "Countryid" = 1 can anyone tell how I can correct it

thanks

3 Answers 3

1

Just change Contains to Equals

var countriesQry = from a in countTbl.AsEnumerable()
                           where a["CountryId"].ToString().Equals(countryId)
                           orderby a["CountryId"]
Sign up to request clarification or add additional context in comments.

2 Comments

yeah i initially thought of that but if the country field has the value "1,22,13" that wont return any results
sorry ill hold my hand up just tried.Equals and it works great thanks
0
var countriesQry = from a in countTbl.AsEnumerable()
                           where a["CountryId"].ToString().Equals(countryId)
                           orderby a["CountryId"]

Comments

0

Try using Any() instead of Contains.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.