DbResultSet.DbException Property
.NET Standard 2.x
Gets the exception when errors occur during the SQL operation.
Namespace: PowerScript.Bridge
Assembly: PowerScript.Bridge.dll
Syntax
public Exception DbException { get; internal set; }
Property Value
System.Exception
The Exception
object which returns the exception during the SQL operation.
Examples
The following code example demonstrates how to use the DbException
property of the DbResultSet
object to get the exception message.
using System;
using SnapObjects.Data;
using PowerScript.Bridge;
namespace Appeon.ApiDoc.DbResultSetExamples
{
public class DbExceptionExample
{
private readonly SchoolContext _context;
public DbExceptionExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// The stored procedure to be executed requires an int-type parameter to be passed in.
// But actually a string-type parameter is passed in.
// This will cause an exception and the exception message will be stored in the
// DbException property of the DbResultSet object.
_context.SqlExecutor.ExecuteProcedure("GetStudentGrades",
out DbResultSet resultSet, ParamValue.New<string>("StudentID", "abc"));
// Shows the error message stored in the result set
Console.WriteLine($"Error Message = {resultSet.DbException.Message}");
/*This code produces the following output:
Error Message = Error converting data type nvarchar to int.
*/
}
}
}
Applies to
.NET Standard
2.x