Call the ExecuteReader Method of a SqlCommand



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

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.