DbResultSet.GetValue<T>(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 T GetValue<T>(int columnIndex);
Parameters
columnIndex
System.Int32
The index number of the column.
Returns
T
Returns the data value of the column. The type T must be consistent with the type of the column.
Examples
The following code example demonstrates how to use the GetValue
generic method 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 Example3()
{
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)
{
// Calls the GetValue generic method to get the values in DbResultSet according to the column number
int enrollmentID = resultSet.GetValue<int>(0);
decimal grade = resultSet.GetValue<decimal>(1);
int courseID = resultSet.GetValue<int>(2);
int studentID = resultSet.GetValue<int>(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