473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Compare two DataRows

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
2 14767
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dominik Luyten | last post by:
Hi, I would like to format certain DataRows in a Windows.Forms.DataGrid. I know how to do that for the columns, but I cannot find a way to assign a specific font, color etc. to a specific kind...
5
by: Nathan Sokalski | last post by:
I am writing an ASP.NET application in which I need to copy DataRows from one DataTable to another. When I use code such as the following: temprows = nodes.Select("state='PA'")...
9
by: Brad | last post by:
I have written some code to manipulate data/records in a MASTER (order header) and DETAIL (order details) tables. What I have written is too extensive to post but essentially trying to: 1....
3
by: cjh999777 | last post by:
Hi, I am new to using databases in vb.net and i have created a accessdatabase called employee it has a key field called employeeID. Ihave gotton as far as creating the dataconnection,...
1
by: adeelanjum2001 | last post by:
I have two datatables with same structure. i want to compare the values in each row. for example: datatable1.rows(0).item(0) = datatable2.rows(0).item(0) one way to compare the rows in datatable...
3
by: creator_bob | last post by:
How do I create an array of datarows from a sorted list? I put a bunch of datarows into a sorted list to sort them. Then I got an array of the sorted elements. However, I cannot typecast them. ...
3
by: =?Utf-8?B?UmljY2FyZG8=?= | last post by:
What is the best method to compare 2 array to knw if each element is equal? Now, i have to compare the datarow.itemarray of 2 datarows wich is equals in structure. I tried to write this routine:...
3
by: sonymathur | last post by:
I'm using two datasets DS1 & DS2 (both hold data with same schema) in VB.Net 1.1 DS1 is main datasets and DS2 is like subset to DS1.Now how should i remove datarows from DS1 that are like in DS2....
8
by: jehugaleahsa | last post by:
Hello: We wrote an entire application where we add our DataRows to our DataTables immediately. However, we have to shut off our constraints to do this. We would like to use detached DataRows to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.