asp.net.ph

SqlCommand.ExecuteReader Method

System.Data.SqlClient Namespace   SqlCommand Class


Sends the CommandText to the Connection and builds an SqlDataReader.

Overload List

1. Sends the CommandText to the Connection and builds an SqlDataReader.

2. Sends the CommandText to the Connection, and builds an SqlDataReader using one of the CommandBehavior values.


Example

The following example illustrates use of the ExecuteReader method.

NOTE: This example uses one of the overloaded versions of ExecuteReader. For other examples that may be available, see the individual overload topics.

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 ( );
}
  C# VB

See Also

SqlCommand Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph