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 |