Show / Hide Table of Contents

    ISqlInsertBuilder.Insert(string table, string schema) Method

    .NET Standard 2.x

    Inserts a row (by a SQL INSERT statement) and specifies the name and the schema of the table or view that will receive the data.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlInsertBuilder Insert(string table, string schema);
    

    Parameters

    table System.String

    The name of the table or view that will receive the data.

    schema System.String

    The schema of the table or view that will receive the data.

    Returns

    SnapObjects.Data.ISqlInsertBuilder

    Returns the current ISqlInsertBuilder object.

    Examples

    The following code example demonstrates how to use the Insert(string table, string schema) method to insert a row to the "Department" table and specify the schema for the "Department" table.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlInsertBuilderExamples
    {
        public class InsertExample
        {
            private SchoolContext _context;
    
            public InsertExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example2()
            {
    
                // Declares SqlInsertBuilder.
                var sqlbuilder = new SqlInsertBuilder();
    
                // Creates a SQL INSERT statement to insert a row to the "Department" table and specify the schema to "dbo".                 
                sqlbuilder.Insert("Department", "dbo")
                    .ColumnValue("DepartmentID", 10)
                    .ColumnValue("Name", "Chinese")
                    .ColumnValue("Budget", 28000m)
                    .ColumnValue("StartDate", DateTime.Now)
                    .ColumnValue("Administrator", 2);
    
                // 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:
                
                Sql Syntax:INSERT INTO [dbo].Department([DepartmentID],
                [Name],
                [Budget],
                [StartDate],
                [Administrator]) VALUES(10,
                N'Chinese',
                28000.0,
                '2018-12-06 08:36:17.410',
                2)
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon