Sends the CommandText to the Connection and builds a DB2DataReader.
Name | Description |
---|---|
ExecuteReader() | Sends the CommandText to the Connection and builds a DB2®DataReader. |
ExecuteReader(CommandBehavior) | Sends the CommandText to the Connection, and builds a DB2DataReader based on the CommandBehavior specified. |
[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();
}