Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 801207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:24:25+00:00 2026-05-14T23:24:25+00:00

This is my first question and first day in Linq so bit difficult day

  • 0

This is my first question and first day in Linq so bit difficult day for me to understand.
I want to fetch some records from database

i.e.

select * from tblDepartment 
where department_id in 
(
   select department_id from tblMap 
   where Guest_Id = @GuestId
)

I have taken two DataTable. i.e. tblDepartment, tblMap

Now I want to fetch this result and want to store it in third DataTable.

How can I do this.

I have been able to construct this query up till now after googling.

var query = from myrow in _dtDepartment.AsEnumerable()
            where myrow.Field<int>("Department_Id") == _departmentId
            select myrow;

Please provide me some link for learning Linq mainly for DataTables and DataSets.

EDIT:

I have got a very similar example here but i m still not able to understand how it is working.
Please put some torch on it.

I want to do this because I am already fetching data from database and dont want to send request again when I already have data. But I want to filter that data based on conditions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:24:26+00:00Added an answer on May 14, 2026 at 11:24 pm

    What you are attempting is not actual LINQ-To-SQL. It is a common misunderstanding. In LINQ-To-SQL you map some tables to entities in a simple way, then at run-time your LINQ query is translated by SQL by the framework and returned as your pre-defined strongly typed entity objects. (I use “entity” as a descriptive term; nothing to do with Entity Framework.) LINQ-To-SQL is something you do instead of ADO.NET.

    What you are doing is a flavor of LINQ-to-object often called “LINQ-To-Dataset”, which I use often. The extension method .AsEnumerable() returns a DataTable’s DataRows in an IEnumerable<DataRow> object, which is very handy. However, with LINQ-To-DataTable, you either (A) won’t have strongly typed objects, or (B) you are taking responsibility for putting your data into strongly typed objects yourself. After you’ve used ADO.NET like you always have, LINQ-to-DataTable is a great way to get your data out of ADO.NET DataTables and into something else, whatever is consuming the data.

    You LINQ query above will take your DataTable, which has already run against the DB, and return an IEnumerable<DataRow>, which is great. Do:

    After your LINQ statement, do:

    For Each DataRow in query
        //Do your stuff
    Next
    

    If you really need a DataTable object in particular at this point, then check this out. But do you really need a DataTable?

    • Good intro to LINQ-To-DataSet (sometimes called LINQ-To-DataTable)
    • Good explanation of LINQ-To-SQL

    And I have to suggest a really great book about LINQ. LINQ rocks. In a .NET world that seems to have too much that we need to learn, LINQ is worth taking the time to really understand. Get: LINQ In Action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my very first question so I am a bit nervous about it
this is my first question to stackoverflow so here it goes... I use cruise
this is my first question here so I hope I can articulate it well
This is my first question so please be patient :) Background: I'm implementing an
Greetings to all! This is my first question here on stackoverflow. I have a
This is a really basic question but this is the first time I've used
I know this question might sound a little cheesy but this is the first
Okay this is a fairly broad question. This is my first App and I'm
This question might not seem programming related at first, but let me explain. I'm
So this question will get technical – eventually – but first check out Hanselminutes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.