ExecutePageReader Method (DbCommandBase)
Returns a specific subset of rows when paging through the results of a query.
The example below shows how to retrieve a part of a table. If this function is called with parameters
startRecord=2 and
maxRecords=3, it returns 3 rows: second, third, and fourth.
public void ExecutePaged(DB2Connection db2Connection, int StartRow, int PageLength)
{
DB2Command db2Command = new DB2Command("SELECT DeptNo, DName, Loc FROM Dept", db2Connection);
db2Connection.Open();
DB2DataReader db2Reader = db2Command.ExecutePageReader(System.Data.CommandBehavior.Default,StartRow,PageLength);
try
{
while (db2Reader.Read())
{
Console.WriteLine(db2Reader.GetInt32(0).ToString() + ", " + db2Reader.GetString(1) + ", " + db2Reader.GetString(2));
}
}
finally
{
db2Reader.Close();
db2Connection.Close();
}
}
Public Sub ExecutePaged(ByVal db2Connection As DB2Connection, ByVal StartRow As Integer, ByVal PageLength As Integer)
Dim db2Command As New DB2Command("SELECT DeptNo, DName, Loc FROM Dept", db2Connection)
db2Connection.Open()
Dim db2Reader As DB2DataReader = db2Command.ExecutePageReader(System.Data.CommandBehavior.Default, StartRow, PageLength)
Try
While db2Reader.Read()
Console.WriteLine(db2Reader.GetInt32(0).ToString() + ", " _
+ db2Reader.GetString(1) + ", " _
+ db2Reader.GetString(2))
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