andrew slaughter
andrew slaughter

Reputation: 1127

asp.net linq .contains "string"

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

Upvotes: 0

Views: 142

Answers (3)

L.Grillo
L.Grillo

Reputation: 981

Try using Any() instead of Contains.

Upvotes: 0

Paul Michaels
Paul Michaels

Reputation: 16705

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

Upvotes: 0

Yograj Gupta
Yograj Gupta

Reputation: 9869

Just change Contains to Equals

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

Upvotes: 1

Related Questions