Solved

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

Posted on 2010-08-26
4
474 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
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now