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

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

LVL 13
RickAsked:
Who is Participating?
 
DhaestConnect With a Mentor Commented:
Try this (swith the brackets)

While reader.Read
                drpDivision.Items.Add(reader.Item("Division").ToString())
End While
0
 
Jini Jose.Net Team LeadCommented:
did u debugged it ?

set a breakpoint in that line and check the values of reader.Item("Division")
0
 
ZhaolaiConnect With a Mentor Commented:
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
 
RickAuthor Commented:
Thanks guys
0
All Courses

From novice to tech pro — start learning today.