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

  • SEARCH
  • Home
  • 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 8550743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:01:25+00:00 2026-06-11T14:01:25+00:00

I have a DataTable containing a list of Id’s I get from the DB.

  • 0

I have a DataTable containing a list of Id’s I get from the DB. What I need to do is get a List<Of Integer>.

This list of integers will be the Id’s in the DataTable, but I need to filter them based on another List<Of Integers>. So I’m basically trying to generate a list of Id’s from the DataTable but only if they exist in my other list of Ids.

I know how to do the Linq To DataSet query, but I’m just not sure if it’s possible to filter it based on another List, here’s some pseudo code to explain what I’m trying to achieve:

List<Of Integer> ExistingList = GetReferenceIds(whatever)
DataTable DBTable = GetAllDatabaseIds(whatever)

List<Of Integer> FilteredList = DBTable.AsEnumerable()
                                    .Where(Column("Id") IN FilteredList).ToList()

Is there an easy way to do this without having to enumerate through the list and check each one?

  • 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-06-11T14:01:27+00:00Added an answer on June 11, 2026 at 2:01 pm

    The most efficient is using Enumerable.Join:

    IEnumerable<int> IDs = from row in DBTable.AsEnumerable()
                 join id in ExistingList
                 on row.Field<int>("Id") equals id 
                 select id;  // selects the id, you could also select the DataRow
    

    Oops! Here’s VB.NET:

    Dim IDs = From row In DBTable
              Join id In ExistingList
              On row.Field(Of Int32)("Id") Equals id
              Select id
    

    Is there a way to do this join which would give me the Id’s NOT in the list?

    Yes, that would be an outer join. But in this case Except is easier (and probably even more efficient):

    Dim dbIDs = DBTable.AsEnumerable().Select(Function(r) r.Field(Of Int32)("Id"))
    Dim notInList As IEnumerable(Of Int32) = dbIDs.Except(ExistingList)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datatable containing system profile names. This table is then assigned as
I am working with VB.NET.. i have a DataTable called QUESTION, containing 3 fields:
I have datatable with column name tag and 100 rows of data.I need to
This is tricky to explain. We have a DataTable that contains a user configurable
I need ideas... I have a classic scenario with a twist, containing the following
I have a List which I create from a DataTabe which only has one
I have a strongly typed dataset containing a datatable with one of the columns
I have a datatable containing 10 columns. I want to select only two columns
I need some help with a linq query. Basically, I have a datatable with
I have a data table I've loaded from a CSV file. I need to

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.