Solved

Linq query with "where" statement

Posted on 2014-12-11
6
92 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 63

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

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 63

Expert Comment

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

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

695 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