Show / Hide Table of Contents

    SqlContext.SetParm<TValue>(int index, TValue value) Method

    .NET Standard 2.x

    Specifies a value for an input parameter in the SqlContext.

    Namespace: PowerScript.Bridge

    Assembly: PowerScript.Bridge.dll

    Syntax

      public void SetParm<TValue>(int index, TValue value)
    

    Parameters

    index System.Int32

    An integer identifying the input parameter descriptor in which you want to set the data.

    value TValue

    The value you want to use to fill the input parameter descriptor identified by index.

    Examples

    The following code example demonstrates how to use the SqlContext object to specify a SQL SELECT statement and use the SetParm method to define the parameter and the type.

    using System;
    using PowerScript.Bridge;
    
    namespace Appeon.ApiDoc.SqlContextExamples
    {
        public class SetParmExample
        {
            private readonly SchoolContext _context;
    
            public SetParmExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example2()
            {
                // Defines the SQL SELECT statement.
                var sql = @"select EnrollmentID, Grade from StudentGrade " +
                           "where StudentID = @StudentID and CourseID=@CourseID";
    
                // Creates the SqlContext object
                var sqlContext = _context.CreateSqlContext(sql);
                // Defines two int-type parameters for the SQL statement
                sqlContext.SetParm<int>(0, 2);
                sqlContext.SetParm<int>(1, 2021);
    
                // Shows the parameters
                Console.WriteLine($"Parameter count = {sqlContext.Parms.Length}, " +
                    $"Value of first parameter = {sqlContext.Parms[0].Value}, " +
                    $"Value of second parameter = {sqlContext.Parms[1].Value}.");
    
                /*This code produces the following output:
    
                Parameter count = 2, Value of first parameter = 2, Value of second parameter = 2021.
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon