Solved

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

Posted on 2010-08-26
4
485 Views
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:

drpDivision.Items.Add(reader.Item("Division")).ToString()



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



        Try

            cnn.Open()

            reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

            drpDivision.Items.Add("")

            While reader.Read
                drpDivision.Items.Add(reader.Item("Division")).ToString()
            End While

Open in new window

0
Comment
Question by:Rick
[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
4 Comments
 
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")
0
 
LVL 17

Assisted Solution

by:Zhaolai
Zhaolai earned 250 total points
ID: 33537219
Try this:

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

Open in new window

0
 
LVL 53

Accepted Solution

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

While reader.Read
                drpDivision.Items.Add(reader.Item("Division").ToString())
End While
0
 
LVL 13

Author Closing Comment

by:Rick
ID: 33541719
Thanks guys
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 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