ExecutePageReader Method (MySqlCommand)
Returns a specific subset of rows when paging through the results of a query.
Returns a specific subset of rows when paging through the results of a query.
Parameters
- behavior
- One of the System.Data.CommandBehavior values.
- startRecord
- Specifies the number of starting record of the set of records to be returned.
- maxRecords
- Specifies total number of records to retrieve.
Return Value
A
MySqlDataReader object with requested records.
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(MySqlConnection myConnection, int StartRow, int PageLength)
{
MySqlCommand myCommand = new MySqlCommand("SELECT * FROM Test.Dept", myConnection);
myConnection.Open();
MySqlDataReader myReader = myCommand.ExecutePageReader(System.Data.CommandBehavior.Default,StartRow,PageLength);
try
{
while (myReader.Read())
{
Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1) + ", " + myReader.GetString(2));
}
}
finally
{
myReader.Close();
myConnection.Close();
}
}
Public Sub ExecutePaged(ByVal myConnection As MySqlConnection, ByVal StartRow As Integer, ByVal PageLength As Integer)
Dim myCommand As New MySqlCommand("SELECT * FROM Test.Dept", myConnection)
myConnection.Open()
Dim myReader As MySqlDataReader = myCommand.ExecutePageReader(System.Data.CommandBehavior.Default, StartRow, PageLength)
Try
While myReader.Read()
Console.WriteLine(myReader.GetInt32(0).ToString() + ", " _
+ myReader.GetString(1) + ", " _
+ myReader.GetString(2))
End While
Finally
myReader.Close()
myConnection.Close()
End Try
End Sub