Compare two DataRows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RB0135

    #1

    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.dat arow.

    Here is the full code:
    Dim thisBindingSour ce As BindingSource = sender
    Dim ThisDataRow As DataRow = thisBindingSour ce.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 ApplicationExce ption("It seems the Position
    Changed event was fired twice for the same row")
    End If

    UpdateRowToData base()
    'track the current row for next
    'PositionChange d 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

    #2
    Re: Compare two DataRows

    Untested, but have you tried

    if ThisDataRow.Equ als(LastDataRow ) ...

    Rick

    "RB0135" <robear@joshie. com.auwrote in message
    news:1185345915 .932857.220200@ i38g2000prf.goo glegroups.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.dat arow.
    >
    Here is the full code:
    Dim thisBindingSour ce As BindingSource = sender
    Dim ThisDataRow As DataRow = thisBindingSour ce.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 ApplicationExce ption("It seems the Position
    Changed event was fired twice for the same row")
    End If
    >
    UpdateRowToData base()
    'track the current row for next
    'PositionChange d 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
    >

    Comment

    • \(O\)enone

      #3
      Re: Compare two DataRows

      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.dat arow.
      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


      Comment

      Working...