Solved

LINQ Query problem

Posted on 2014-02-26
5
379 Views
Last Modified: 2016-02-10
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.
0
Comment
Question by:5281
  • 2
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 39890010
Is customerID a numeric or a string?  If numeric, try  c.customerID = 100
0
 

Author Comment

by:5281
ID: 39890024
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()
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 450 total points
ID: 39890031
Have you tried each of the other 2 criteria (store number and state) separately to see if one of them cancels everything out?
0
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 50 total points
ID: 39890085
Are you getting an exception at run time?
0
 

Author Comment

by:5281
ID: 39890200
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.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question