Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problems counting the number of rows in DataTable

Posted on 2013-10-29
2
Medium Priority
?
154 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 2000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 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