DbResultSet.GetValue<T>(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 T GetValue<T>(string columnName);
Parameters
columnName
System.String
The name 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 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 Example4()
{
int id = 2;
// Executes a stored procedure and 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 name
int enrollmentID = resultSet.GetValue<int>("EnrollmentID");
decimal grade = resultSet.GetValue<decimal>("Grade");
int courseID = resultSet.GetValue<int>("CourseID");
int studentID = (int)resultSet.GetValue<int>("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