Looping through Dataset

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

    #1

    Looping through Dataset

    I am using the code below to loop through a dataset for reporting
    stats. The problem I have is when I modify a row of data, it counts
    that row 3 times the next time i run the loop. I believe it has
    something to do with the way datasets keep track of changes.

    For Each row As DataRow In CustomerDataSet .Tables(0).Rows
    Dim dtRedeemed As DateTime
    Dim intLocation As Integer
    If Not row("RedeemedOn ") Is DBNull.Value Then
    dtRedeemed = CDate(row("Rede emedOn"))
    End If
    If Not row("LocationID ") Is DBNull.Value Then
    intLocation = CStr(row("Locat ionID"))
    End If

    If intLocation = LocationID Then
    iTotal += 1
    If dtRedeemed.Date = Now.Date Then
    iToday += 1
    End If
    End If
    Next

  • tomb

    #2
    Re: Looping through Dataset

    Be sure to call CustomerDataSet .AcceptChanges

    T

    Charlie Brown wrote:
    [color=blue]
    >I am using the code below to loop through a dataset for reporting
    >stats. The problem I have is when I modify a row of data, it counts
    >that row 3 times the next time i run the loop. I believe it has
    >something to do with the way datasets keep track of changes.
    >
    > For Each row As DataRow In CustomerDataSet .Tables(0).Rows
    > Dim dtRedeemed As DateTime
    > Dim intLocation As Integer
    > If Not row("RedeemedOn ") Is DBNull.Value Then
    > dtRedeemed = CDate(row("Rede emedOn"))
    > End If
    > If Not row("LocationID ") Is DBNull.Value Then
    > intLocation = CStr(row("Locat ionID"))
    > End If
    >
    > If intLocation = LocationID Then
    > iTotal += 1
    > If dtRedeemed.Date = Now.Date Then
    > iToday += 1
    > End If
    > End If
    > Next
    >
    >
    >[/color]

    Comment

    Working...