Object reference not set to an instance of an object ERROR, PLEASE HELP!!!!
Posted on 2005-05-11
Hi Everybody, I’m a new user with VB.net
I have created a procedure so that each time the user leave the comboBox Control this code happens:
Private Sub MyComboBox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbTapeId.Leave
Dim sqlStr As String = "SELECT * FROM tapes where tape_id = " & cmbTapeId.Text
' Create data adapter object
Dim dr As SqlDataReader
dc.Connection = SqlConnection1 'SqlConnection1 was created in the VS desigh ' THIS IS WHERE THE ERROR COME UP
dc.CommandText = sqlStr
dc.CommandType = CommandType.Text
dr = dc.ExecuteReader()
'reading from the datareader
txtTapeDecs.Text = dr(dr.GetOrdinal("tape_description")).ToString()
dc = Nothing
This Error Appears only on the second time it enters the Sub.
What to do?