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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:06:13+00:00 2026-06-10T08:06:13+00:00

I have some DataTables loaded into memory from various sources (SQL and MS Access),

  • 0

I have some DataTables loaded into memory from various sources (SQL and MS Access), and each dataset has several columns, with only a subset of columns that are the same between each dataset. I’m working on some data synchronization code, and I want to compare these data tables, but only compare them based on the columns they have in common. If I had to I could probably do this with lots of loops, but I want to get more comfortable with LINQ and have more concise code.

Thus far I’ve managed to get a list of column names from each datatable, and used Intersect to get the list of column names common to both of them, like this:

private string[] Common_ColumnNames {
    get {
        // get column names from source & destination data
        string[] src_columnNames = 
        (from dc in _srcDataTable.Columns.Cast<DataColumn>() 
        select dc.ColumnName).ToArray();

        string[] dest_columnNames = 
        (from dc in _destDataTable.Columns.Cast<DataColumn>() 
        select dc.ColumnName).ToArray();

        // find the column names common between the two data sets 
        // - these are the columns to be compared when synchronizing
        return src_columnNames.Intersect( dest_columnNames ).ToArray();                
    }
}

Now I’m stuck… I need to select all rows from each DataTable, but only with those common columns. In my head I see this working a couple different ways:

1) select all rows from a datatable, and passing in my desired column list string[] variable to tell LINQ what columns I want

2) select all rows from a datatable, and use some lambda function (also fairly new to me) to remove the unwanted columns from each row, and outputing a new datatable with some dropped columns.

Any advice/suggestions on how to pull this off would be appreciated. Thanks!

  • 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-10T08:06:15+00:00Added an answer on June 10, 2026 at 8:06 am

    Well, it is not LinQ, but it is pretty simple with a DataView

    string[] commonCols = obj.Common_Columns;
    DataView myTableView = new DataView(srcDataTable); 
    DataTable srcReducedTable = myTableView.ToTable(false, commonCols); 
    

    MSDN refs

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

Sidebar

Related Questions

I have some DataGridViews each displaying one DataTable from a DataSet with multiple DataTables.
I have a DataSet with some DataTables that are linked together with DataRelations (classic
I have a DataSet with some Datatables and I am saving this DataSet as
I have a treeList, loaded with data from SQL DB. The logigs in sql
The problem simplified: I have a DataSet with some datatables... I have a Winforms
I have some data loaded as a np.ndarray and need to convert it to
i have some script..it lies in some direktori : var/www/html/dataTables-1.6/media/css/demo_page.css how to put in
I have created this query to fetch some result from database. Here is my
I have modified the dataTables filter input into a Jquery Mobile search filter ,
I have a data access layer which returns DataSets/DataTables by executing Stored Procedure. Everything

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.