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.
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();
try
{
while(db2Reader.Read())
{
Console.WriteLine(db2Reader.GetString(0));
}
}
finally
{
db2Reader.Close();
db2Connection.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()
Try
While db2Reader.Read()
Console.WriteLine(db2Reader.GetString(0))
End While
Finally
db2Reader.Close()
db2Connection.Close()
End Try
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