Show / Hide Table of Contents

    ISqlUpdateBuilder.SetValue(string columnName, object value) Method

    .NET Standard 2.x

    Specifies a column to be updated with a new value.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlUpdateBuilder SetValue(string columnName, object value);
    

    Parameters

    columnName System.String

    The name of the column to be updated.

    value System.String

    The value to be updated to the column.

    Returns

    SnapObjects.Data.ISqlUpdateBuilder

    Returns the current ISqlUpdateBuilder object.

    Examples

    The following code example demonstrates how to use the SetValue method.It modifies the Name values to "Chinese" for the record where DepartmentID=1 in the "Department" table.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlUpdateBuilderExamples
    {
        public class SetValueExample
        {
            private SchoolContext _context;
    
            public SetValueExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlUpdateBuilder();
    
                // Modifies the Name value to "Chinese" for the record where DepartmentID=1 in the "Department" table.
                sqlbuilder.Update("Department")
                       .SetValue("Name","Chinese")
                       .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] = N'Chinese'
                WHERE ([DepartmentID] = 1)
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon