DbResultSet.GetDataType(int columnIndex) Method
.NET Standard 2.x
Gets the data type in .NET for the specified column in the result set.
Namespace: PowerScript.Bridge
Assembly: PowerScript.Bridge.dll
Syntax
public abstract Type GetDataType(int columnIndex);
Parameters
columnIndex System.Int32
The index number of the column.
Returns
System.Type
Returns the data type in .NET.
Examples
The following code example demonstrates how to use the GetDataType method to get the data type of the second column in the DbResultSet object.
using System;
using SnapObjects.Data;
using PowerScript.Bridge;
namespace Appeon.ApiDoc.DbResultSetExamples
{
public class GetDataTypeExample
{
private readonly SchoolContext _context;
public GetDataTypeExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example1()
{
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));
resultSet.Next();
if (resultSet.SqlCode == 0)
{
// Gets the data type of the second column
var type = resultSet.GetDataType(1);
// If the data type is decimal?, show the value
if (type == typeof(decimal?))
{
decimal? Grade = resultSet.GetValue<decimal?>(1);
Console.WriteLine($"Grade = {Grade}");
}
}
resultSet.Close();
/*This code produces the following output:
Grade = 4.00
*/
}
}
}
Applies to
.NET Standard
2.x