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(SqlConnection sqlConnection, int StartRow, int PageLength)
{
SqlCommand sqlCommand = new SqlCommand("SELECT DeptNo, DName, Loc FROM Test.Dept", sqlConnection);
sqlConnection.Open();
SqlDataReader sqlReader = sqlCommand.ExecutePageReader(System.Data.CommandBehavior.Default,StartRow,PageLength);
try
{
while (sqlReader.Read())
{
Console.WriteLine(sqlReader.GetInt32(0).ToString() + ", " + sqlReader.GetString(1) + ", " + sqlReader.GetString(2));
}
}
finally
{
sqlReader.Close();
sqlConnection.Close();
}
} |
|
|---|
Public Sub ExecutePaged(ByVal sqlConnection As SqlConnection, ByVal StartRow As Integer, ByVal PageLength As Integer)
Dim sqlCommand As New SqlCommand("SELECT DeptNo, DName, Loc FROM Test.Dept", sqlConnection)
sqlConnection.Open()
Dim sqlReader As SqlDataReader = sqlCommand.ExecutePageReader(System.Data.CommandBehavior.Default, StartRow, PageLength)
Try
While sqlReader.Read()
Console.WriteLine(sqlReader.GetInt32(0).ToString() + ", " _
+ sqlReader.GetString(1) + ", " _
+ sqlReader.GetString(2))
End While
Finally
sqlReader.Close()
sqlConnection.Close()
End Try
End Sub |