Improve company productivity with a Business Account.Sign Up


Object reference not set to an instance of an object (vs2010 web app with vb)

Posted on 2010-08-26
Medium Priority
Last Modified: 2013-11-27
What's wrong with this?
I keep getting a "Object reference not set to an instance of an object." on this line:


Dim cnn As New SqlConnection(strConnString)

        Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM Master_Divisions", cnn)
        'cmd.CommandType = CommandType.Text

        Dim reader As SqlDataReader



            reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)


            While reader.Read
            End While

Open in new window

Question by:Rick
LVL 10

Expert Comment

by:Jini Jose
ID: 33536934
did u debugged it ?

set a breakpoint in that line and check the values of reader.Item("Division")
LVL 17

Assisted Solution

Zhaolai earned 1000 total points
ID: 33537219
Try this:

            While reader.Read
                If reader.Item("Division") IsNot Nothing Then
                End If
            End While

Open in new window

LVL 53

Accepted Solution

Dhaest earned 1000 total points
ID: 33541156
Try this (swith the brackets)

While reader.Read
End While
LVL 13

Author Closing Comment

ID: 33541719
Thanks guys

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

606 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