SqlBuilder.Insert(string table) Method
.NET Standard 2.x | Current Version (1.0.1) 
Creates an ISqlInsertBuilder object for building the 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
public static 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 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) method to insert a row to 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 Example1()
{
// Creates an INSERT statement to insert a record to the "Department" table.
var query = 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 = query.ToSqlString(_context);
Console.WriteLine(sql);
/*This code produces the following output:
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