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 / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

Compare two DataRows

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RB0135 - 25 Jul 2007 07:45 GMT
Hi,

I need to compare two complete datarows. In C# it is a simple matter
of if (datarow1 == datarow2) ....

But, if I try If DataRow1 = Datarow2 then.... I get an error stating
that the "operator '=' is not defined for type system.data.datarow.

Here is the full code:
       Dim thisBindingSource As BindingSource = sender
       Dim ThisDataRow As DataRow = thisBindingSource.Current.Row
       If ThisDataRow = LastDataRow Then
           ' we need to avoid to write a datarow to the
           ' database when it is still processed. Otherwise
           ' we get a problem with the event handling of
           'the DataTable.
           Throw New ApplicationException("It seems the Position
Changed event was fired twice for the same row")
       End If

       UpdateRowToDatabase()
       'track the current row for next
       'PositionChanged event
       LastDataRow = ThisDataRow

What I am trying to do is trap a double fire of the bindingsource
PositionChanged method. I have the C# code which works fine, but I
need the VB code equivelant.

Any ideas/Help?

Thanks,
Robert
Rick - 25 Jul 2007 12:57 GMT
Untested, but have you tried

if ThisDataRow.Equals(LastDataRow) ...

Rick

> Hi,
>
[quoted text clipped - 29 lines]
> Thanks,
> Robert
(O)enone - 25 Jul 2007 15:32 GMT
> I need to compare two complete datarows. In C# it is a simple matter
> of if (datarow1 == datarow2) ....
>
> But, if I try If DataRow1 = Datarow2 then.... I get an error stating
> that the "operator '=' is not defined for type system.data.datarow.

Use "=" to compare values.

Use "Is" to compare references.

The VB.NET equivalent of your C# code is:

\\\
   If datarow1 Is datarow2 Then
       [...]
   End If
///

This will of course determine whether two DataRow references point to the
same physical object, and not whether two different DataRow objects contain
the same values...

HTH,

Signature

(O)enone


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.