Show / Hide Table of Contents

    SqlBuilder.Insert(string table, string schema) Method

    .NET Standard 2.x | Current Version (1.0.1)

    0.5.0-alpha

    1.0.1 (current)

    Creates an ISqlDeleteBuilder object for building the 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

     public static 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 a newly created ISqlInsertBuilder object which can be used to build the SQL INSERT statement.

    Remarks

    The data type of the inserted value must be the same as that of the corresponding column in the database.

    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.SqlBuilderExamples
    {
        public class InsertExample
        {
            private SchoolContext _context;
    
            public InsertExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example2()
            {
    
                // Creates an INSERT statement to insert a record to the "Department" table and specify the schema as "dbo".
                var query = SqlBuilder
                    .Insert("Department", "dbo")
                    .ColumnValue("DepartmentID", 20)
                    .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 = query.ToSqlString(_context);
    
                Console.WriteLine(sql);
                
                /*This code produces the following output:
                
                INSERT INTO [dbo].Department([DepartmentID],
                [Name],
                [Budget],
                [StartDate],
                [Administrator]) VALUES(20,
                N'Chinese',
                28000.0,
                '2018-12-06 08:36:17.410',
                2)
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon