Sends the CommandText to the Connection and builds a DB2DataReader.
[Visual Basic]
Overloads Public Function ExecuteReader() As DB2DataReader
[C#]
public DB2DataReader
ExecuteReader();
[C++]
public: DB2DataReader
* ExecuteReader();
[JScript]
public function ExecuteReader() : DB2DataReader;
A DB2DataReader object.
To prepare for the execution of a stored procedure, set the CommandType property to StoredProcedure, and set the CommandText property to the name of the stored procedure. Now, when you call ExecuteReader, the application will execute this stored procedure.
You can concurrently access data from multiple DB2DataReader instances that use the same DB2Connection instance. Each DB2DataReader instance must be associated with its own DB2Command instance.
[Visual Basic, C#] The following example creates a DB2Command by passing a string with an SQL SELECT statement, and a connection string. The SQL is then executed by calling ExecuteReader.
[Visual Basic]
Public Sub CreateMyDB2DataReader(mySelectQuery As String, _
myConnectionString As String)
Dim myConnection As New DB2Connection(myConnectionString)
Dim myCommand As New DB2Command(mySelectQuery, myConnection)
myCommand.Connection.Open()
Dim myReader As DB2DataReader = myCommand.ExecuteReader()
Try
While myReader.Read()
Console.WriteLine(myReader.GetString(0))
End While
Finally
myReader.Close()
myConnection.Close()
End Try
End Sub
[C#]
public void CreateMyDB2DataReader(string mySelectQuery,string myConnectionString)
{
DB2Connection myConnection = new DB2Connection(myConnectionString);
DB2Command myCommand = new DB2Command(mySelectQuery, myConnection);
myCommand.Connection.Open();
DB2DataReader myReader = myCommand.ExecuteReader();
try
{
while(myReader.Read())
{
Console.WriteLine(myReader.GetString(0));
}
}
finally
{
myReader.Close();
myConnection.Close();
}
}