Show / Hide Table of Contents

    ParamValue.New<Type>(string name, ParameterDirection direction) Method

    .NET Standard 2.x

    Creates a new ParamValue object and specifies the name and the direction type of the parameter.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public static ParamValue New<Type>(string name, ParameterDirection direction)
    

    Parameters

    name System.String

    The name of the parameter.

    direction System.Data.ParameterDirection

    (Optional) The direction type of the parameter.

    The default is ParameterDirection.Input.

    Returns

    SnapObjects.Data.ParamValue

    Returns the newly created ParamValue object.

    Examples

    The following code example creates a ParamValue object and specifies its name and 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 NewExample
        {
            private readonly SchoolContext _context;
    
            public NewExample(SchoolContext context)
            {
                _context = context;
            }
    
            public void Example3()
            {
                // Sets the parameter values.
                // The parameter direction defaults to ParameterDirection.Input,
                // so you can omit it.
                var idParam = ParamValue.New<string>("id", "4");
    
                // The parameter 'Name' is Output type.
                var nameParam = ParamValue.New<string>(
                    "name", ParameterDirection.InputOutput);
    
                // Specifies the procedure to be executed.
                var procedureName = "GetDepartmentName";
    
                /* StoredProcedure GetDepartmentName:
                
                CREATE PROCEDURE[dbo].[GetDepartmentName]
                @ID int,
                @Name nvarchar(50) OUTPUT
                AS
                SELECT @Name = Name FROM Department
                WHERE DepartmentID = @ID
    
                GO
                */
    
                // Executes the SQL statement and gets the department by nameParam.
                _context.SqlExecutor.ExecuteProcedure(
                   procedureName, idParam, nameParam);
    
                Console.WriteLine("Department Name: {0}", nameParam.Value);
    
                /*This code produces the following output:
    
                Department Name: Economics
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon