Show / Hide Table of Contents

    DbResultSet.GetValue(int columnIndex) Method

    .NET Standard 2.x

    Gets the data value of the specified column from the result set.

    Namespace: PowerScript.Bridge

    Assembly: PowerScript.Bridge.dll

    Syntax

    public abstract object GetValue(int columnIndex);
    

    Parameters

    columnIndex System.Int32

    The index number of the column.

    Returns

    System.Object

    Returns the data value of the column.

    Examples

    The following code example demonstrates how to get the values stored in the DbResultSet object according to the column number.

    using System;
    using SnapObjects.Data;
    using PowerScript.Bridge;
    
    namespace Appeon.ApiDoc.DbResultSetExamples
    {
        public class GetValueExample
        {
            private readonly SchoolContext _context;
    
            public GetValueExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example1()
            {
                int id = 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", id));
    
                resultSet.Next();
    
                // Shows the result set returned from the stored procedure
                while (resultSet.SqlCode == 0)
                {
                    // Gets the values in DbResultSet according to the column number
                    int enrollmentID = (int)resultSet.GetValue(0);
                    decimal grade = (decimal)resultSet.GetValue(1);
                    int courseID = (int)resultSet.GetValue(2);
                    int studentID = (int)resultSet.GetValue(3);
    
                    Console.WriteLine($"EnrollmentID: {enrollmentID}, " +
                        $"Grade: {grade}, " +
                        $"CourseID: {courseID}, " +
                        $"StudentID: {studentID}");
    
                    resultSet.Next();
                }
    
                // Closes the DbResultSet object
                resultSet.Close();
    
                /*This code produces the following output:
                
                EnrollmentID: 1, Grade: 4.00, CourseID: 2021, StudentID: 2
                EnrollmentID: 2, Grade: 3.50, CourseID: 2030, StudentID: 2
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon