DB2 Version 9.7 for Linux, UNIX, and Windows

Reading result sets from an application using the IBM Data Server Provider for .NET

When using the IBM Data Server Provider for .NET, the reading the result sets is done through a DB2DataReader object. The DB2DataReader method, Read() is used to advance to the next row in the result set.

About this task

The methods GetString(), GetInt32(), GetDecimal(), and other methods for all of the available data types are used to extract data from the individual columns of output. The DB2DataReader's Close() method is used to close the DB2DataReader object, which should always be done when reading the output is finished.

Reading a result set in C#:
// assume a DB2DataReader reader
Int16 deptnum = 0;
String location="";

// Output the results of the query
while(reader.Read())
{
  deptnum = reader.GetInt16(0);
  location = reader.GetString(1);
  Console.WriteLine("    " + deptnum + " " + location);
}
reader.Close();
Reading a result set in Visual Basic .NET:
' assume a DB2DataReader reader
Dim deptnum As Int16 = 0
Dim location As String ""

' Output the results of the query
Do While (reader.Read())
  deptnum = reader.GetInt16(0)
  location = reader.GetString(1)
  Console.WriteLine("    " & deptnum & " " & location)
Loop
reader.Close();