SqlResult.DbException Property
.NET Standard 2.x
Gets the exception information of parameter when executing the SQL statement.
Namespace: PowerScript.Bridge
Assembly: PowerScript.Bridge.dll
Syntax
public Exception DbException { get; internal set; }
Property Value
Exception
The exception information of parameter when executing the SQL statement.
Examples
The following code example demonstrates how to use the DbException
property of the SqlResult
object to get the exception message for executing the SQL statement.
using System;
using PowerScript.Bridge;
namespace Appeon.ApiDoc.SqlResultExamples
{
public class DbExceptionExample
{
private readonly SchoolContext _context;
public DbExceptionExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Defines a SQL statement which updates the Name field in the Department table.
string sql = "UPDATE Department SET Name = @name where DepartmentID = 1";
// The SQL statement to be executed requires a parameter to be passed in.
// But no parameter is passed in when SQL is executed.
// This will cause an exception and the exception message will be stored
// in the DbException property of the SqlResult object.
_context.SqlExecutor.ExecuteNonQuery(sql, out SqlResult sqlResult);
Console.WriteLine($"Error Message = {sqlResult.DbException.Message}");
/*This code produces the following output:
Error Message = The number of parameters does not match.
*/
}
}
}
Applies to
.NET Standard
2.x