Show / Hide Table of Contents

    DbResultSet.GetValue(string columnName) 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(string columnName);
    

    Parameters

    columnName System.String

    The name 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 name.

    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 Example2()
            {
                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 name
                    int enrollmentID = (int)resultSet.GetValue("EnrollmentID");
                    decimal grade = (decimal)resultSet.GetValue("Grade");
                    int courseID = (int)resultSet.GetValue("CourseID");
                    int studentID = (int)resultSet.GetValue("StudentID");
    
                    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