Skip to content

InsertRow

InsertRow method allows inserting a single row in a custom data table. This is an equivalent of SQL INSERT query.

This method is useful if you need to save some particular data related to each sent email, e.g. date or GUID.

1. Method signature

InsertRow(table, columns, values)

Parameter definition:

NameTypeDescription
tablestringRequired. Table name.
columnsarray of stringRequired. Array of column names in table we insert a record to. Submitting the list is required to handle cases where some columns are omitted (e.g. those with default values) or supplied in different order than in the table.
valuesarray of objectRequired. Array of column values. Values are passed as object, so multiple types can be passed (numeric, text etc). See examples.

2. Usage and examples

You can call InsertRow method using curly braces syntax. You may put in anywhere in the email template code since its output is empty string.

Example 1 – the most simple call

${InsertRow('MyTable', new string[] {'MyColumn'}, new object[] {'foobar'})}

Equivalent SQL query:

INSERT INTO MyTable (MyColumn) VALUES ('foobar')

This assumes we have a simple table with one column.

Example 2 – inserting a record to table with multiple columns of different types

${InsertRow('MyTable', new string[] {'MyIntColumn', 'MyTextColumn', 'MyDateColumn'}, new object[] {123, 'foobar', new System.DateTime(2015, 1, 26, 14, 0, 0)})}

Equivalent SQL query:

INSERT INTO MyTable (MyIntColumn, MyTextColumn, MyDateColumn) VALUES (123, 'foobar', '2015-01-26 14:00:00')

Of course, it is possible to use any of available predefined variables, snippets or subscriber properties as inserted values.

On this page
To top