Show / Hide Table of Contents

    SqlResult.ErrorText Property

    .NET Standard 2.x

    Gets the text of the database vendor's error message corresponding to the error code.

    Namespace: PowerScript.Bridge

    Assembly: PowerScript.Bridge.dll

    Syntax

    public string ErrorText { get => _errorText; internal set => _errorText = value ?? String.Empty;}
    

    Property Value

    string

    The text of the database vendor's error message corresponding to the error code.

    Examples

    The following code example demonstrates how to use the ErrorText 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 ErrorTextExample
        {
            private readonly SchoolContext _context;
    
            public ErrorTextExample(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 ErrorText property of the SqlResult object.
                _context.SqlExecutor.ExecuteNonQuery(sql, out SqlResult sqlResult);
    
                Console.WriteLine($"ErrorText = {sqlResult.ErrorText}");
    
                /*This code produces the following output:
                
                ErrorText = The number of parameters does not match.
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon