Show / Hide Table of Contents

    DbResultSet.Prior() Method

    .NET Standard 2.x

    Gets the data value of the previous row from the result set. Similar to the cursor FETCH PRIOR function.

    Namespace: PowerScript.Bridge

    Assembly: PowerScript.Bridge.dll

    Syntax

      public abstract void Prior();
    

    Examples

    The following code example demonstrates how to execute a stored procedure and get the result set (stored in the DbResultSet object) and how to get the previous row of data from the result set.

    using System;
    using SnapObjects.Data;
    using PowerScript.Bridge;
    
    namespace Appeon.ApiDoc.DbResultSetExamples
    {
        public class PriorExample
        {
            private readonly SchoolContext _context;
    
            public PriorExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example()
            {
                int studentID = 2;
    
                // Executes a stored procedure which gets the data of StudentGrade table according to StudentID.
                _context.SqlExecutor.ExecuteProcedure("GetStudentGrades",
                    out DbResultSet resultSet, ParamValue.New<int>("StudentID", studentID));
    
                // Gets the last row of data.
                resultSet.Last ();
                if (resultSet.SqlCode == 0)
                {
                    Console.WriteLine($"EnrollmentID: {resultSet.GetValue<int>("EnrollmentID")}, " +
                        $"Grade: {resultSet.GetValue<decimal>("Grade")}, " +
                        $"CourseID: {resultSet.GetValue<int>("CourseID")}, " +
                        $"StudentID: {resultSet.GetValue<int>("StudentID")}");
                }
    
                // Gets the previous row of the last row
                resultSet.Prior();
                if (resultSet.SqlCode == 0)
                {
                    Console.WriteLine($"EnrollmentID: {resultSet.GetValue<int>("EnrollmentID")}, " +
                        $"Grade: {resultSet.GetValue<decimal>("Grade")}, " +
                        $"CourseID: {resultSet.GetValue<int>("CourseID")}, " +
                        $"StudentID: {resultSet.GetValue<int>("StudentID")}");
                }
    
                // Closes the resultSet object.
                resultSet.Close();
    
                /*This code produces the following output:
                
                EnrollmentID: 2, Grade: 3.50, CourseID: 2030, StudentID: 2
                EnrollmentID: 1, Grade: 4.00, CourseID: 2021, StudentID: 2
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon