Show / Hide Table of Contents

    SqlBuilder.Update(string table) Method

    .NET Standard 2.x

    Creates an ISqlUpdateBuilder object for building a SQL UPDATE statement, and specifies the name of the table or view from which the rows are to be updated.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

     public static ISqlUpdateBuilder Update(string table);
    

    Parameters

    table System.String

    The name of the table or view from which the rows are to be updated.

    Returns

    SnapObjects.Data.ISqlUpdateBuilder

    Returns a newly created ISqlUpdateBuilder object which can be used to build the SQL UPDATE statement.

    Examples

    The following code example demonstrates how to use the Update(string table, string schema) method. It updates the Name value to "Chinese" for the record where DepartmentID = 1 in the "Department" table.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.SqlBuilderExamples
    {
        public class UpdateExample
        {
            private SchoolContext _context;
    
            public UpdateExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example1()
            {
    
                // Modifies the Name value to "Chinese" for the record where DepartmentID=1 in the "Department" table.    
                var query = SqlBuilder
                    .Update("Department")
                    .SetValue("Name", "Chinese")
                    .Where("DepartmentID", "1");
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = query.ToSqlString(_context);
    
                Console.WriteLine(sql);
                
                /*This code example 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