dotConnect for SQL Server Documentation
Devart.Data.SqlServer Namespace / SqlCommand Class / ExecutePageReader Method
One of the System.Data.CommandBehavior values.
Specifies the number of starting record of the set of records to be returned.
Specifies total number of records to retrieve.
Example

In This Topic
    ExecutePageReader Method (SqlCommand)
    In This Topic
    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.
    Syntax
    'Declaration
     
    Public Shadows Function ExecutePageReader( _
       ByVal behavior As CommandBehavior, _
       ByVal startRecord As Integer, _
       ByVal maxRecords As Integer _
    ) As SqlDataReader
    public new SqlDataReader ExecutePageReader( 
       CommandBehavior behavior,
       int startRecord,
       int maxRecords
    )

    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 SqlDataReader object with requested records.
    Remarks

    Use method ExecutePageReader when you want to retrieve not the whole dataset but some part of it that begins with given row number and has certain quantity of rows. This is especially useful when working with large amounts of data.

    If you want to retrieve all data in a dataset, use ExecuteReader() instead.

    Note: This method is not supported in .NET Standard 1.3 compatible assembly. It is available only in the assembly for full .NET Framework and .NET Standard 2.0 compatible assembly.

    Example
    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 myConnection, int StartRow, int PageLength)
    {
      SqlCommand myCommand = new SqlCommand("SELECT * FROM Test.Dept", myConnection);
      myConnection.Open();
      SqlDataReader 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 SqlConnection, ByVal StartRow As Integer, ByVal PageLength As Integer)
      Dim myCommand As New SqlCommand("SELECT * FROM Test.Dept", myConnection)
      myConnection.Open()
      Dim myReader As SqlDataReader = 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
    Requirements

    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

    See Also