Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Why are these NOT equal?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Bartel - 27 Feb 2008 16:34 GMT
I have a routine to compare the current value with the original value of
fields in a Datatable.  The code loops through each column to compare the
values and builds an update statement for those columns that have changed.

But for some reason, the Datetime fields are evaluating as not equal when
they are!  (I just retreived the row and did nothing with the Datetime
columns, and in the debugger "a" and "b" look the same).

Here is the code:

           DataRow Row = MyTable.Rows[0];

           foreach (DataColumn column in Columns)
           {
               a = Row[column.ColumnName, DataRowVersion.Current];
               b = Row[column.ColumnName, DataRowVersion.Original];

               if (b != a)
               {
                   //Build Update Statement
               }
           }

Any thoughts anyone?

Thanks in advance.

Bob Bartel
Jon Skeet [C# MVP] - 27 Feb 2008 16:43 GMT
> I have a routine to compare the current value with the original value of
> fields in a Datatable.  The code loops through each column to compare the
[quoted text clipped - 20 lines]
>
> Any thoughts anyone?

How are a and b declared? They're probably as "object" in which case
the value is the boxed value and you're just checking for referential
equality.

Try object.Equals(a, b)

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Bob Bartel - 27 Feb 2008 17:02 GMT
Thank you.  You nailed it!

bob

>> I have a routine to compare the current value with the original value of
>> fields in a Datatable.  The code loops through each column to compare the
[quoted text clipped - 27 lines]
>
> Try object.Equals(a, b)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.