void ExecuteReaderDemo ( string query, string connString ) {
SqlConnection myConn = new SqlConnection ( connString );
SqlCommand myCommand = new SqlCommand ( query, myConn );
myCommand.Connection.Open ( );
SqlDataReader myReader =
myCommand.ExecuteReader ( CommandBehavior.CloseConnection );
while ( myReader.Read ( ) ) {
Response.Write ( myReader.GetString ( 0 ) );
}
myReader.Close ( );
myConn.Close ( );
}
Public Sub ExecuteReaderDemo ( query As String, connString As String )
Dim myConn As New SqlConnection ( connString )
Dim myCommand As New SqlCommand ( query, myConn )
myCommand.Connection.Open ( )
Dim myReader As SqlDataReader = _
myCommand.ExecuteReader ( CommandBehavior.CloseConnection )
While myReader.Read ( )
Response.Write ( myReader.GetString ( 0 ) )
End While
myReader.Close ( )
myConn.Close ( )
End Sub |