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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:34:56+00:00 2026-05-24T04:34:56+00:00

I have two dataTables as follows 1) dtExistingZipCodeInDB (data from database) 2) dtCSVExcelSource (data

  • 0

I have two dataTables as follows

1) dtExistingZipCodeInDB (data from database)

2) dtCSVExcelSource (data from csv source which is to be processed)

I have two requirements

1) List all the retired zip codes (zip codes that are present in dtExistingZipCodeInDB but not in dtCSVExcelSource)

2) UnChanged zip codes (zip codes that are present both in dtExistingZipCodeInDB and dtCSVExcelSource)

I can use the Merge to get the retired zip codes. How do I get the unchanged zip codes?

Framework: .Net 3.0

//Note: dtExistingZipCodeInDB and dtCSVExcelSource has the same columns
dtCSVExcelSource.Merge(dtExistingZipCodeInDB);
DataTable dtRetiredZipDataTable = dtCSVExcelSource.GetChanges();
string retiredZipCodes = GetStringFromDataTable(dtRetiredZipDataTable, "ZipCode");

Thanks

Lijo

  • 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-24T04:34:56+00:00Added an answer on May 24, 2026 at 4:34 am

    With the .NET 3.0 requirement, the Intersect LINQ extension method is not available, but you can provide your own extension method.

    All you need is the MatchingRows extension method (see below in the demo code) and then do:

     IEnumerable<DataRow> unchangedZipCodes = dtExistingZipCodeInDB.MatchingRows(dtCSVExcelSource, "ZipCode");
    

    Then you can loop over unchangedZipCodes, which will contain only those rows with ZipCodes in common between dtExistingZipCodeInDB and dtCSVExcelSource.

    Below is demo code I wrote using LINQPad. I love LINQPad — it’s great for proof of concept or scratchpadding/sandboxing some code quickly. But it is not required for the solution to this question.

    void Main()
    {
        string colname = "ZipCode";
    
        var dt = new DataTable();
        dt.Columns.Add(colname, typeof(string));
        dt.Rows.Add(new [] { "12345" } );
        dt.Rows.Add(new [] { "67890" } );
        dt.Rows.Add(new [] { "40291" } );
    
        var dt2 = new DataTable();
        dt2.Columns.Add(colname, typeof(string));
        dt2.Rows.Add(new [] { "12345" } );
        dt2.Rows.Add(new [] { "83791" } );
        dt2.Rows.Add(new [] { "24520" } );
        dt2.Rows.Add(new [] { "48023" } );
        dt2.Rows.Add(new [] { "67890" } );
    
    /// With .NET 3.5 LINQ extensions, it can be done inline.
    //  var results = dt.AsEnumerable()
    //          .Select(r => r.Field<string>(colname))
    //          .Intersect(dt2.AsEnumerable()
    //              .Select(r => r.Field<string>(colname)));
    //  Console.Write(String.Join(", ", results.ToArray()));
    
        var results = dt.MatchingRows(dt2, colname);
        foreach (DataRow r in results)
            Console.WriteLine(r[colname]);
    }
    
    public static class Extensions
    {
        /// With .NET 3.0 and no LINQ, create an extension method using yield.
        public static IEnumerable<DataRow> MatchingRows(this DataTable dt, DataTable dtCompare, string colName)
        {
            foreach (DataRow r in dt.Rows)
            {
                if (dtCompare.Select(String.Format("{0} = {1}", colName, r[(colName)])).Length > 0)
                    yield return r;
            }
        }
    }
    

    Outputs:

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

Sidebar

Related Questions

I have two DataTables, A and B , produced from CSV files. I need
I have a very simple linq query that gets data from two datatables (orderHeader
Suppose I have two .NET DataTables populated as follows, where ID is the primary
i have two DataTables one with a hughe List of Results and one with
I have a report that needs to get data from two logical areas of
I have two DataTables dt1 and dt2. Each table have different data in them
I Have two datatables as follows Table1 -------------------------------- Id | Batch | Qty -----------------------------
I have two datatables. One is to display names. Another contains three <h:selectOneMenu> .
I have two DataTables. First is DataTable NameAddressPhones = new DataTable(); with Three columns
I have two DataTables one is Primary Table and the rest is a sub

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.