Fetches data from a database using the SqlCommand.ExecuteReader method of an existing data command.
'Assembly: System.Data.dll
'Assembly: System.Xml.dll
'Namespace: System.Data
'Namespace: System.Data.SqlClient
'Dim conn AS SqlConnection = "conn"
'Dim cmd AS SqlCommand = "cmd"
Dim reader As SqlDataReader
Dim previousConnectionState As ConnectionState = conn.State
Try
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
reader = cmd.ExecuteReader()
Using reader
While reader.Read
' Process SprocResults datareader here.
ProcessSprocResult
End While
End Using
Finally
If previousConnectionState = ConnectionState.Closed Then
conn.Close()
End If
End Try