Solved

Linq query with "where" statement

Posted on 2014-12-11
6
82 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

757 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

19 Experts available now in Live!

Get 1:1 Help Now