DB2Command.ExecuteReader (CommandBehavior) Method
Sends the CommandText to the Connection, and builds a DB2DataReader using one of the CommandBehavior values.
- Namespace:
IBM.Data.DB2
- Assembly:
IBM.Data.DB2
(inIBM.Data.DB2.dll
)
Syntax
[Visual Basic]
Public Function ExecuteReader( _
ByVal behavior As CommandBehavior _
) As DB2DataReader
[C#]
public DB2DataReader
ExecuteReader(
CommandBehavior behavior
);
[C++]
public: DB2DataReader
* ExecuteReader(
CommandBehavior behavior
);
[JScript]
public function ExecuteReader(
behavior : CommandBehavior
) : DB2DataReader
;
Parameters
- behavior
- One of the System.Data.CommandBehavior values.
Return value
A DB2®DataReader instance.
Remarks
If you expect your SQL statement to return only a single row, specifying SingleRow as the CommandBehavior value may improve application performance.
The DB2DataReader supports a special mode that enables large binary values to be read efficiently. For more information, see the SequentialAccess setting for CommandBehavior.
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.
Example
[Visual Basic, C#] The following example creates a DB2Command , then executes it by passing a string that is an SQL SELECT statement, and a string to use to connect to the database. CommandBehavior is then set to CloseConnection.
[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(CommandBehavior.CloseConnection)
While myReader.Read()
Console.WriteLine(myReader.GetString(0))
End While
myReader.Close()
myConnection.Close()
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(CommandBehavior.CloseConnection);
while(myReader.Read())
{
Console.WriteLine(myReader.GetString(0));
}
myReader.Close();
myConnection.Close();
}