DbResultSet.First() Method
.NET Standard 2.x
Gets the first row of data from the result set. Similar to the cursor FETCH FIRST
function.
Namespace: PowerScript.Bridge
Assembly: PowerScript.Bridge.dll
Syntax
public abstract void First();
Examples
The following code example executes a stored procedure and gets the data of the first row from the result set. The result set returned by the stored procedure is stored in the DbResultSet
object.
using System;
using SnapObjects.Data;
using PowerScript.Bridge;
namespace Appeon.ApiDoc.DbResultSetExamples
{
public class FirstExample
{
private readonly SchoolContext _context;
public FirstExample(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 data of the first row from the result set.
resultSet.First();
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: 1, Grade: 4.00, CourseID: 2021, StudentID: 2
*/
}
}
}
Applies to
.NET Standard
2.x