You can use the nextresult method of the datareader object to retrieve the next result set. If the return value of this method is false, it indicates that the last result set has been reached. For example:
Public Void Page_load (Object sender, eventargs E)
{
// Connect to the student database of the Local Computer
String strconn = " Server = (local); database = test; trusted_connection = Yes " ;
Sqlconnection CN = New Sqlconnection (strconn );
//Open connection
CN. open ();
// Create a command object, which contains two query statements
String S1 = " Select ID from student; " ;
String S2 = " Select name from student " ;
Sqlcommand cm = New Sqlcommand (S1 + S2, CN );
//Create a datareader object
Sqldatareader Dr=Cm. executereader ();
// Read the query results of an SQL statement in sequence using the read method of datareader
Do
{
// Read the query results of an SQL statement in sequence using the read method of datareader
While (Dr. Read ())
{
Object [] Cols = New Object [ 2 ];
Int N = Dr. getvalues (Cols );
Message. Text = Message. Text + " / " + Dr [ 0 ]. Tostring ();
}
// Use the nextresult () method of datareader to read the query results of the next SQL statement.
Message. Text = Message. Text + " **** " ;
}
While (Dr. nextresult ());
// Disable Dr
Dr. Close ();
// Close connection
CN. Close ();
}
The results are as follows:
/2001010348/2001011780/2001296531 */Zhang San/Li Si/Wang 'er ****