Solved

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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