By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

Compare two DataRows

P: n/a
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

Jul 25 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Untested, but have you tried

if ThisDataRow.Equals(LastDataRow) ...

Rick

"RB0135" <ro****@joshie.com.auwrote in message
news:11**********************@i38g2000prf.googlegr oups.com...
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

Jul 25 '07 #2

P: n/a
RB0135 wrote:
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,

--

(O)enone
Jul 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.