LINQ Query problem

5281
5281 used Ask the Experts™
on
I have a LINK Query, it is suppose to select a record, but it just doesn't select anything out.  What's wrong with my query?

Dim query As List(Of Class1) = (From c In customers _
 Where c.customerID = "100" AndAlso c.StoreNumber = "B100" AndAlso c.State = "GA" _
                                                         Select c).ToList()

I want the customer whose customerID is 100, and storenumber is B100 and state is Georgia to be selected, but nothing come out.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jens FiedererTest Developer/Validator

Commented:
Is customerID a numeric or a string?  If numeric, try  c.customerID = 100

Author

Commented:
customerID is a string.  If I just select customerID like below, it would work, if I added other criteria, it doesn't select anything out.

Dim query As List(Of Class1) = (From c In customers _
                                                     Where c.customerID = "100" _
                                                         Select c).ToList()
Test Developer/Validator
Commented:
Have you tried each of the other 2 criteria (store number and state) separately to see if one of them cancels everything out?
Fernando SotoRetired
Distinguished Expert 2017
Commented:
Are you getting an exception at run time?

Author

Commented:
Oh, yes.  When I tried seperately, one of criterial storenumber cancel out everything.  I found I did not use Trim() function when I read them into List.  So it may contain space.  Thank you for your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial