ISqlInsertBuilder.ColumnValue(string columnName, object value) Method
.NET Standard 2.x
Specifies the value to be inserted into the column of a table.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlInsertBuilder ColumnValue(string columnName, object value);
Parameters
columnName
System.String
The name of the column into which data will be inserted.
value
System.Object
The value to be inserted into the column.
Returns
SnapObjects.Data.ISqlInsertBuilder
Returns the current ISqlInsertBuilder
object.
Examples
The following code example demonstrates how to use the ColumnValue(string columnName, object value) method to insert fixed values to the row.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlInsertBuilderExamples
{
public class ColumnValueExample
{
private SchoolContext _context;
public ColumnValueExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example()
{
// Declares SqlInsertBuilder.
// 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:
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