DbResultSet Class
.NET Standard 2.x
Stores the results and states of the SQL operations.
Namespace: PowerScript.Bridge
Assembly: PowerScript.Bridge.dll
Syntax
public abstract class DbResultSet;
Properties
Name | Return Type | Description |
---|---|---|
ColumnCount | short | Gets the number of the property columns in the result set. |
DbException | Exception | Gets the exception when errors occur during the SQL operation. |
ErrorText | string | Gets the error message when errors occur during the SQL operation. |
RowCount | int | Gets the number of rows in the result set. |
SqlCode | int | Gets the return code of the SQL operation. |
Methods
Name | Return Type | Description |
---|---|---|
Close() | void | Closes the result set. |
First() | void | Gets the first row of data from the result set. |
GetDataType(int columnIndex) | type | Gets the data type in .NET for the specified column in the result set. |
GetDataType(string columnName) | type | Gets the data type in .NET for the specified column in the result set. |
GetPbDataType(int columnIndex) | PbDataType | Gets the data type in PowerBuilder for the specified column in the result set. |
GetPbDataType(string columnName) | PbDataType | Gets the data type in PowerBuilder for the specified column in the result set. |
GetValue(int columnIndex) | object | Gets the data value of the specified column from the result set. |
GetValue(string columnName) | object | Gets the data value of the specified column from the result set. |
GetValue<T>(int columnIndex) | T | Gets the data value of the specified column from the result set. |
GetValue<T>(string columnName) | T | Gets the data value of the specified column from the result set. |
Last() | void | Gets the data value of the last row from the result set. |
Next() | void | Gets the data value of the next row from the result set. |
Prior() | void | Gets the data value of the previous row from the result set. |
Examples
The following code example executes a stored procedure and returns the result set which is stored in the DbResultSet
object.
using System;
using SnapObjects.Data;
using PowerScript.Bridge;
namespace Appeon.ApiDoc.DbResultSetExamples
{
public class DbResultSetExample
{
private readonly SchoolContext _context;
public DbResultSetExample(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 a row of data
resultSet.Next();
// Shows the result set returned from the stored procedure
while (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")}");
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
*/
}
}
}