Question : 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()


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
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

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

Try this (swith the brackets)

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