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 mySqlConnection, int StartRow, int PageLength)
{
MySqlCommand mySqlCommand = new MySqlCommand("SELECT * FROM Test.Dept", mySqlConnection);
mySqlConnection.Open();
MySqlDataReader mySqlReader = mySqlCommand.ExecutePageReader(System.Data.CommandBehavior.Default,StartRow,PageLength);
try
{
while (mySqlReader.Read())
{
Console.WriteLine(mySqlReader.GetInt32(0) + ", " + mySqlReader.GetString(1) + ", " + mySqlReader.GetString(2));
}
}
finally
{
mySqlReader.Close();
mySqlConnection.Close();
}
} |
|
|---|
Public Sub ExecutePaged(ByVal mySqlConnection As MySqlConnection, ByVal StartRow As Integer, ByVal PageLength As Integer)
Dim mySqlCommand As New MySqlCommand("SELECT * FROM Test.Dept", mySqlConnection)
mySqlConnection.Open()
Dim mySqlReader As MySqlDataReader = mySqlCommand.ExecutePageReader(System.Data.CommandBehavior.Default, StartRow, PageLength)
Try
While mySqlReader.Read()
Console.WriteLine(mySqlReader.GetInt32(0).ToString() + ", " _
+ mySqlReader.GetString(1) + ", " _
+ mySqlReader.GetString(2))
End While
Finally
mySqlReader.Close()
mySqlConnection.Close()
End Try
End Sub |