Can anyone tell me how to test for an open datareader? I'm getting the following error: "There is already an open datareader associated with this command."
The code I'm using is below. I have no problem calling he procedure the first time through, but when it gets call after being called a second time. I ran it through debug and I can see that the datareader is closed, not to mention the variable reader is declared local, so it should be disposed of at the end of the procedure.
Any help would be appreciated.
Tom
The code I'm using is below. I have no problem calling he procedure the first time through, but when it gets call after being called a second time. I ran it through debug and I can see that the datareader is closed, not to mention the variable reader is declared local, so it should be disposed of at the end of the procedure.
Any help would be appreciated.
Tom
VB.NET:
Private Sub LoadIncidentTypesSelected()
Dim reader As SqlDataReader
Dim dt As New DataTable
Try
If Not IsNothing(Me.lbIncidentSelected.DataSource) Then
Me.lbIncidentSelected.DataSource = Nothing
End If
Me.lbIncidentSelected.Items.Clear()
reader = clsIncident.GetIncidentTypesSelected
Dim tb As New DataTable
tb.Load(reader)
Me.lbIncidentSelected.DisplayMember = "IncidentType"
Me.lbIncidentSelected.ValueMember = "itID"
Me.lbIncidentSelected.DataSource = tb
reader.Close()
Me.lbIncidentSelected.SelectedIndex = -1
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub