ExecuteReader(CommandBehavior) Method
The following example creates a
DB2Command, then executes it by passing a string that is SQL SELECT statement, and a string to use to connect to the data source. The
System.Data.CommandBehavior is then set to CloseConnection.
public void CreateDB2DataReader(string mySelectQuery,string db2ConnectionString)
{
DB2Connection db2Connection = new DB2Connection(db2ConnectionString);
DB2Command db2Command = new DB2Command(mySelectQuery, db2Connection);
db2Command.Connection.Open();
DB2DataReader db2Reader = db2Command.ExecuteReader(CommandBehavior.CloseConnection);
while(db2Reader.Read())
{
Console.WriteLine(db2Reader.GetString(0));
}
db2Reader.Close();
}
Public Sub CreateDB2DataReader(mySelectQuery As String, _
db2ConnectionString As String)
Dim db2Connection As New DB2Connection(db2ConnectionString)
Dim db2Command As New DB2Command(mySelectQuery, db2Connection)
db2Command.Connection.Open()
Dim db2Reader As DB2DataReader = db2Command.ExecuteReader(CommandBehavior.CloseConnection)
While db2Reader.Read()
Console.WriteLine(db2Reader.GetString(0))
End While
db2Reader.Close()
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2