Show / Hide Table of Contents

    ParamValue.Output(string name, int size, Type dataType) 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(string name, int size, Type dataType)
    

    Parameters

    name System.String

    The name of the parameter.

    size System.Int32

    The size of the parameter.

    dataType Type

    The type 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 async void Example4()
            {
                // 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.
                ParamValue nameParam = ParamValue.Output("name", 100, typeof(string));
                
                // Asynchronously Executes the SQL statement and gets the department by
                // nameParam.
                int rowAffected = await _context.SqlExecutor.ExecuteProcedureAsync(
                        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