Show / Hide Table of Contents

    ParamValue.New(string name, object value) Method

    .NET Standard 2.x

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

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public static ParamValue New(string name, object value)
    

    Parameters

    name System.String

    The name of the parameter.

    value System.Object

    The value of the parameter.

    Returns

    SnapObjects.Data.ParamValue

    Returns the newly created ParamValue object.

    Examples

    The following code example creates a ParamValue object and specifies its name and value. The direction is Input by default.

    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 Example1()
            {
                // Declares a string variable and sets its value.
                string data = "Economics";
    
                // Creates a ParamValue object and specifies its name and value.
                // The direction is input by default.
                var param = ParamValue.New("deptName", data);
    
                // Gets and shows the name, value and direction of the ParamValue object.
                Console.WriteLine("ParamValue.Name = {0}", param.Name);
                Console.WriteLine("ParamValue.Value = {0}", param.Value);
                Console.WriteLine("ParamValue.Direction = {0}", param.Direction);
    
                // Defines a SqlQueryBuilder object
                var sqlBuilder = new SqlQueryBuilder();
                sqlBuilder.AddParameters(
                   SqlBuilder.Parameter<string>("deptName"));
    
                sqlBuilder.Select("name")
                        .From("Department")
                        .Where("name", "@deptName");
    
                // Passes it the ParamValue object when querying data.
                var result = _context.SqlExecutor.Scalar<string>(sqlBuilder, param);
    
                /*This code produces the following output:
                
                ParamValue.Name = data1
                ParamValue.Value = Economics
                ParamValue.Direction = Input
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon