Solved

Linq query with "where" statement

Posted on 2014-12-11
6
84 Views
Last Modified: 2016-02-15
Hello,

i'm using the following linq query:

var query = from tbl1 in dt.AsEnumerable()
     select new { ID = tbl1["1"], Name = tbl1["3"]}   ;

Open in new window


This works fine. How could i use the SQL "where" Statement like this?

var query = from tbl1 in dt_Sachkonto.AsEnumerable()
           select new { ID = tbl1["1"], Name = tbl1["3"]  where tbl1["1"].ToString() == "400"}   ;

Open in new window



This should select all records with ID = 400. But it doesn't work.

Thank you very much
Kind Regards
Bounty
0
Comment
Question by:bounty457
  • 3
  • 3
6 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40494575
Try it like this.

var query = from tbl1 in dt_Sachkonto.AsEnumerable()
            where tbl1["1"].ToString() == "400" 
            select new 
            { 
              ID = tbl1["1"], 
              Name = tbl1["3"]
            };

Open in new window

0
 
LVL 1

Author Comment

by:bounty457
ID: 40494618
Nice, thank you very much, it works.

Kind Regrads
Bounty
0
 
LVL 1

Author Comment

by:bounty457
ID: 40494640
I've requested that this question be closed as follows:

Accepted answer: 0 points for bounty457's comment #a40494618

for the following reason:

Great
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40494641
Hi Bounty;

I suspect that the solution I posted work for you but you have closed this question by assigning zero points to yourself but did not assign any points to the solution that you stated works. Can you please close the question by assigning the correct solution the points.

Thank you.
0
 
LVL 1

Author Closing Comment

by:bounty457
ID: 40494681
Really good work. :-)
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40494693
Thank you. 👍
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In C#, how would you convert a byte array to its integer value equivalent? 12 38
Access properties in nested observable collections 8 23
DateTimepicker 4 33
Error on link 14 37
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now