?
Solved

Linq query with "where" statement

Posted on 2014-12-11
6
Medium Priority
?
96 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 2000 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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!
This video teaches viewers about errors in exception handling.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

752 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