Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-08-26
4
Medium Priority
?
488 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 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

715 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