Home All Groups Group Topic Archive Search About

Looping through Dataset

Author
24 May 2006 6:19 PM
Charlie Brown
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("RedeemedOn"))
                End If
                If Not row("LocationID") Is DBNull.Value Then
                    intLocation = CStr(row("LocationID"))
                End If

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

Author
24 May 2006 11:15 PM
tomb
Be sure to call  CustomerDataSet.AcceptChanges

T

Charlie Brown wrote:

Show quoteHide quote
>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("RedeemedOn"))
>                End If
>                If Not row("LocationID") Is DBNull.Value Then
>                    intLocation = CStr(row("LocationID"))
>                End If
>
>                If intLocation = LocationID Then
>                    iTotal += 1
>                    If dtRedeemed.Date = Now.Date Then
>                        iToday += 1
>                    End If
>                End If
>            Next
>

>