Show / Hide Table of Contents

    ISqlInsertBuilder.Insert(string table) Method

    .NET Standard 2.x

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

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlInsertBuilder Insert(string table);
    

    Parameters

    table System.String

    The name 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) method to insert a row to 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 Example1()
            {
    
                // Declares SqlInsertBuilder.
                var sqlbuilder = new SqlInsertBuilder();
    
                // Creates a SQL INSERT statement to insert a row to the "Department" table and insert fixed values to the row.                 
                sqlbuilder.Insert("Department")
                    .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 Department([DepartmentID],
                [Name],
                [Budget],
                [StartDate],
                [Administrator]) VALUES(10,
                N'Chinese',
                28000.0,
                '2018-12-05 16:59:12.371',
                2)
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon