Show / Hide Table of Contents

    ISqlUpdateBuilder.Update(string table) Method

    .NET Standard 2.x

    Creates 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

      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 the current ISqlUpdateBuilder object.

    Examples

    The following code example demonstrates how to use the Update(string table) 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.ISqlUpdateBuilderExamples
    {
        public class UpdateExample
        {
            private SchoolContext _context;
    
            public UpdateExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example1()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlUpdateBuilder();
    
                // Changes the value of Name 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