Solved

Problems counting the number of rows in DataTable

Posted on 2013-10-29
2
147 Views
Last Modified: 2013-10-30
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?
0
Comment
Question by:TPLLimited
2 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 39609943
Why not just use objDT.Rows.Count.ToString instead of using a foreach?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39610401
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question