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 7441735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:03:52+00:00 2026-05-29T11:03:52+00:00

i have a array list of unique Ids ex 1,2,3,4…. and a DataTable with

  • 0

i have a array list of unique Ids

ex 1,2,3,4....

and a DataTable with Records with the above IDs

ID    Name
1     abc
2     xxx
3     aaa
4     bbb
5     eee
6     fff

i need to filter the data table as per the array list content

ex: if array list contain 1,2

then the DataTable should be filtered only to contain those two records.is there any option on DataTable that i could do this other than running the DataTable inside For Loop and getting each DataRow?

  • 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-29T11:03:54+00:00Added an answer on May 29, 2026 at 11:03 am

    You can use Linq to filter and potentially create a new DataTable.

    var filtered = 
        table.AsEnumerable()
            .Where(r => list.Contains(r.Field<int>("ID")))
            .CopyToDataTable();
    

    Given a list containing { 1, 2 }, the filtered table will contain the rows { { 1, “abc” }, { 2, “xxx” } }

    Side note: While you can use ArrayLists, it is preferrable to use the generic counterpart System.Collections.Generic.List<T> in new code written in .NET. Generics were introduced as part of .NET 2.0 / C# 2.0 / VB 8 / Visual Studio 2005. The present editions on the market are .NET 4.0 / C# 4.0 / VB 10 / Visual Studio 2010. ArrayLists are effectively obsolete except in the case of supporting code originating in earlier versions of the langauge and framework.

    Also, if the list is particularly large, it might be worth first loading it into a HashSet<T> prior to the query, as it will be more performant when using a Contains method.


    Full working code demonstration:

    var table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));
    table.Rows.Add(1, "abc");
    table.Rows.Add(2, "xxx");
    table.Rows.Add(3, "aaa");
    table.Rows.Add(4, "bbb");
    table.Rows.Add(5, "eee");
    table.Rows.Add(6, "fff");
    
    // var list = new ArrayList(); // do not prefer
    var list = new List<int>();
    list.Add(1);
    list.Add(2);
    
    var filtered =
        table.AsEnumerable()
            .Where(r => list.Contains(r.Field<int>("ID")))
            .CopyToDataTable();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array list of objects in my application. private static ArrayList<Player> userList=new
Closed as exact duplicate of this question . I have an array/list of elements.
I have an array containing a list of files. I want to sort it
I have an array which is a list of domains, I want to print
I have an array that contains a list of vertices which I copy to
i have 3 Array X,Y,Risk. i added a list generic (listtraining). if i click
I have an array of strings var controlsToGet = new[] {lblHome,lblContact}; I have List<LanguageControl>
Let's say I have an array of primitives or a list of objects, doesn't
I have an array called $times . It is a list of small numbers
In .NET, both array and list have Enumerable as ancestor, so a method that

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.