Link to home
Start Free TrialLog in
Avatar of TPLLimited
TPLLimited

asked on

Problems counting the number of rows in DataTable

Hi

I am currently trying to create a function to count the number of rows held in a DataTable however I keep getting an Object reference not set to an instance of an object error

 Function itemcount() As Integer


        Dim itemcounter As Integer = 0

        For Each Me.objDR In objDT.Rows
            itemcounter = itemcounter + 1
        Next

        Return itemcounter

    End Function

Open in new window


Can anyone help with this please?
ASKER CERTIFIED SOLUTION
Avatar of dustock
dustock
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Éric Moreau
I agree that you should really use the Count method.


>>For Each Me.objDR In objDT.Rows

your iterator (objDR) should be a new variable:

For Each dr as DataRow In objDT.Rows