Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2976
  • Last Modified:

Simple LINQ select statement

What's wrong with this LINQ? I get 6 errors; "; expected" and "invalid expression term in".

I think the syntax is correct. I have using Sytem.LINQ on top of the page. I have also imported the namespace that contians the LINQ context.

EContext dc = new EContext();
 
        var p = from c in dc.LSite //error here under "c", under "in" and under "dc"
                where c.Code != "GBL"  //error here looking for ; at the end.
                select c;
 
        foreach (var values in p)
        {
            lbSites.Attributes.Add(values.Code, values.Name);
        }

Open in new window

0
Camillia
Asked:
Camillia
  • 2
1 Solution
 
naspinskiCommented:
try this
EContext dc = new EContext();
var p = from c in dc.LSite // if c is still getting errors, try a different variable name (might alreaday be used)
           where !c.Code.Equals("GBL") //you are comparing strings here 
           select c;
 
foreach (var values in p)
  lbSites.Attributes.Add(values.Code, values.Name);

Open in new window

0
 
CamilliaAuthor Commented:
let me try and will post back. Thanks
0
 
CamilliaAuthor Commented:
you were right ...  i changed to "equal" but that "c" was also giving an error. Changed it and it works. Thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now