Show / Hide Table of Contents

    ISqlUpdateBuilder.Set(string columnName, ISqlParameter parameter) Method

    .NET Standard 2.x

    Specifies the value of a column to be updated with a SQL parameter.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

     ISqlUpdateBuilder Set(string columnName, ISqlParameter parameter);
    

    Parameters

    columnName System.String

    The name of the column to be updated.

    parameter SnapObjects.Data.ISqlParameter

    An ISqlParameter object which represents a SQL parameter.

    It can be created by calling the SqlBuilder.Parameter method.

    Returns

    SnapObjects.Data.ISqlUpdateBuilder

    Returns the current ISqlUpdateBuilder object.

    Examples

    The following code example demonstrates how to use the Set(string columnName, ISqlParam parameter) method.It modifies the value of the "Name" column for the record whose DepartmentID=1 in the "Department" table using the value of an input parameter.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlUpdateBuilderExamples
    {
        public class SetExample
        {
            private SchoolContext _context;
    
            public SetExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example1()
            {
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlUpdateBuilder();
    
                // Modifies the value of the "Name" column for the record whose DepartmentID=1 
                // in the "Department" table dynamically using an input parameter.    
                sqlbuilder.Update("Department")
                       .Set("Name", SqlBuilder.Parameter<string>())
                       .Where("DepartmentID", "1");
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
                
                /*This code produces the following output:
                
                UPDATE [Department] SET [Name] = @p0
                WHERE ([DepartmentID] = 1)
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon