Creatio development guide
PDF
This documentation is valid for Creatio version 7.11.0. We recommend using the newest version of Creatio documentation.

Composing add data queries

Glossary Item Box

The Insert class is used to add data to the bpm'online database.

The Insert class constructor uses the following objects as parameters:

  • User connection (Insert (UserConnection)).
  • Other object Insert (Insert (Insert)). This will create a copy of an Insert request included in the parameter.
Here is a number of examples.

    Examples of simple requests

    Example 1.

    ShowC#

    var insert = new Insert(userConnection).Into("Contact")
            .Set("Name", Column.Parameter("ParameterNameValue"))
            .Set("Address", Column.Parameter("ParameterAddressValue")); 
    

    ShowMS SQL

    INSERT INTO [dbo].[Contact] ([Name], [Address]) VALUES (@P1, @P2)

    Example 2

    ShowC#

    var insert = new Insert(userConnection).Into("Contact")
            .Set("Name", Column.Const("NameValue"))
            .Set("Address", Column.Const("AddressValue")); 
    

    ShowMS SQL

    INSERT INTO [dbo].[Contact] ([Name], [Address]) VALUES ('NameValue', 'AddressValue')

    Example 3

    ShowC#

    var insert = new Insert(userConnection).Into("Contact")
            .Set("Name", Func.IsNull(Column.Parameter(string.Empty), Column.Parameter("ParameterValue"))); 
    

    ShowMS SQL

    INSERT INTO [dbo].[Contact] ([Name]) VALUES (ISNULL(@P1, @P2))

    Examples of requests with conditions

    Example 1

    ShowC#

    var insert = new Insert(userConnection).Into("City")
            .Set("CreatedById",
                 new Select(userConnection).Top(1)
                     .Column("Id")
                     .From("Contact")
                     .Where("Name").IsEqual(Column.Parameter("Supervisor")))
            .Set("ModifiedById",
                 new Select(userConnection).Top(1)
                     .Column("Id")
                     .From("Contact")
                     .Where("Name").IsEqual(Column.Parameter("User1"))); 
    

    ShowMS SQL

    INSERT INTO [dbo].[City] ([CreatedById], [ModifiedById])

    VALUES((SELECT TOP 1 [Id]

    FROM [dbo].[Contact]

    WHERE [Name] = @P1),

    (SELECT TOP 1 [Id]

    FROM [dbo].[Contact]

    WHERE [Name] = @P2))

    © bpm'online 2002-2018.

    Did you find this information useful?

    How can we improve it?