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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:28:03+00:00 2026-06-09T08:28:03+00:00

Good evening, I’m building a kind of cache comparing two datatable (the last read

  • 0

Good evening,

I’m building a kind of cache comparing two datatable (the last read and the one I need to write) and retrieving only modified rows.
I’m using DataRowComparer.Default as Equality Comparer, but it has wrong aim comparing rows with many fields.

It works perfectly with 3 columns table with short text values, but comparing long text descriptions it fails returning the whole table even if I change a single char.

The code is very simple:

var diffDs = ds.Tables[0].AsEnumerable().Except(cachedTable.AsEnumerable(), DataRowComparer.Default);

Ideas?
Thanks!

Update:
manually debugging I was able to compare ds.Tables[0].AsEnumerable() rows vs cachedtable.AsEnumerable() rows: absolutely equals but different for DataRowComparer Except. I’ve deleted any DateTime column trying to avoid Format differences without success.
Intersection doesn’t work too.

Update 2:
Except doesn’t work with empty/null fields. They seem to be different for the IEqualityComparer.

  • 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-09T08:28:05+00:00Added an answer on June 9, 2026 at 8:28 am

    I found a solution:

    DataRowComparer code works like this:

    internal static bool AreEqual(object a, object b)
        {
            if (Object.ReferenceEquals(a, b))
            {   // same reference or (null, null) or (DBNull.Value, DBNull.Value)
                return true;
            }
            if (Object.ReferenceEquals(a, null) || Object.ReferenceEquals(a, DBNull.Value) ||
                Object.ReferenceEquals(b, null) || Object.ReferenceEquals(b, DBNull.Value))
            {   // (null, non-null) or (null, DBNull.Value) or vice versa
                return false;
            }
            return (a.Equals(b) || (a.GetType().IsArray && CompareArray((Array)a, b as Array)));
        }
    

    As you can see null values and DBNull are differently considered and null==DBNull is always false. Obviously an empty string looks like null field, but it’s not DBNull.
    So, two tables apparently similar are different due to this null values.
    My solution parses ds.Tables[0] while constructing from xml source (this is the one with empty strings and null values) and operates a substitution with System.Convert.DBNull

    Now the comparison works perfectly.

    P.S. \n and \r\n are also different if you build a datatable from sql query or from xml source. Easy to solve assumed the null/DBNull solution above.

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

Sidebar

Related Questions

Good evening, i need to know how can i have one .h file that
Good evening, I have one table, with a timestamp column, then I have a
Good Evening, I'm building a website which will will look something like this: So
Good evening all, I'm trying to write a method that creates and returns a
good evening, i need to check if the input match my regex or not
Good evening, I wrote the code below in C to read and print from
Good evening guys. I'm currently trying to get started on development of a project
Good evening, I'm having an issue with Masonry. This is all my relevant code:
Good evening everyone, I was hoping you could help with an Objective-C question I
Good evening, I would like to have a navigation bar which is centralised 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.