Solved

Problems counting the number of rows in DataTable

Posted on 2013-10-29
2
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

724 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