Show / Hide Table of Contents

    ParamValue.Output<TType>(string name, int size) Method

    .NET Standard 2.x

    Creates a new ParamValue object as the output parameter of a stored procedure.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public static ParamValue Output<TType>(string name, int size)
    

    Type Parameters

    TType

    The datatype of the parameter value.

    Parameters

    name System.String

    The name of the parameter.

    size System.Int32

    The size of the parameter.

    Returns

    SnapObjects.Data.ParamValue

    Returns a newly created ParamValue object.

    Examples

    The following code example creates a ParamValue object and specifies its name and Output direction, then uses it together with SqlExecutor.

    using Appeon.ApiDoc.Models.School;
    using SnapObjects.Data;
    using System;
    using System.Data;
    
    namespace Appeon.ApiDoc.ParamValueExamples
    {
        public class OutputExample
        {
            private readonly SchoolContext _context;
            
            public OutputExample(SchoolContext context)
            {
                _context = context;
            }
    
            public void Example2()
            {
                // Specifies the procedure to be executed.
                string procedureName = "GetDepartmentName";
                /* StoredProcedure GetDepartmentName:
                
                CREATE PROCEDURE[dbo].[GetDepartmentName]
                @ID int,
                @Name nvarchar(50) OUTPUT
                AS
                SELECT @Name = Name FROM Department
                WHERE DepartmentID = @ID
                
                GO
                */
                
                ParamValue idParam = ParamValue.Input<string>("id", "4");
                
                // The parameter 'Name' is Output type and size is 100.
                ParamValue nameParam = ParamValue.Output<string>("name", 100);
                
                // Executes the SQL statement and gets the department by
                // nameParam.
                int rowAffected = _context.SqlExecutor.ExecuteProcedure(
                        procedureName, idParam, nameParam);
                        
                Console.WriteLine("ParamValue.Value = {0}", nameParam.Value);
                
                /*This code produces the following output:
                
                    ParamValue.Value = Economics
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon