Show / Hide Table of Contents

    SqlResult Class

    .NET Standard 2.x

    SqlResult is used to store the result of SQL operations.

    Namespace: PowerScript.Bridge

    Assembly: PowerScript.Bridge.dll

    Syntax

     public class SqlResult;
    

    Constructors

    Name Description
    SqlResult(int sqlCode, int affectedCount = 0) Initializes an instance of the SqlResult object.

    Properties

    Name Return Type Description
    AffectedCount int The number of rows affected by the most recent SQL operation.
    DbException Exception Gets the exceptional information of parameter when executing the SQL statement.
    ErrorText string Gets the text of the database vendor's error message corresponding to the error code.
    SqlCode int Gets the success or failure code of the most recent SQL operation.

    Examples

    The following code example demonstrates how to use the SqlResult object to store the execution result of the SQL statement.

    using System;
    using PowerScript.Bridge;
    
    namespace Appeon.ApiDoc.SqlResultExamples
    {
        public class SqlResultExample
        {
            private readonly SchoolContext _context;
    
            public SqlResultExample(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";
                // Defines the parameter for the SQL statement.
                string name = "Department name";
    
                // Defines a SqlResult object and sets the value of SqlCode to -1.
                SqlResult sqlResult = new SqlResult(-1);
    
                // Calls ExecuteNonQuery to execute the Update statement.
                _context.SqlExecutor.ExecuteNonQuery(sql, out sqlResult, name);
    
                // Shows the values of AffectedCount and SqlCode stored in the SqlResult object.
                Console.WriteLine($"SqlCode = {sqlResult.SqlCode}, " +
                    $"AffectedCount = {sqlResult.AffectedCount}");
    
                /*This code produces the following output:
                
                SqlCode = 0, AffectedCount = 1
                */
            }
        }
    }
    
    Back to top Generated by Appeon