dotConnect for Salesforce Marketing Cloud Documentation
On this page
    Using Parameters
    On this page

    dotConnect for Salesforce Marketing Cloud enhances SQL handling capabilities through the use of parameters in SQL queries. You can make execution of a query or stored procedure very flexible using several techniques. This article describes some basics you must know when working with parameters in dotConnect for Salesforce Marketing Cloud, as well as parameters synchronization and some nuances related to the use of stored procedures.

    Parameter Basics

    In general, a parameter is a placeholder for a variable that contains a value of a certain type when a general-purpose query is executed, or for arguments and return values when a function is executed. A parameter is represented by the ExactTargetParameter class. All parameters that take part in query execution constitute a collection that can be accessed through the ExactTargetCommand.Parameters property.

    Parameters in the query text must correspond to the names of the ExactTargetParameter instances in the collection. Named parameters are declared using the ':' or '@' prefix followed by the parameter name. Use the name of the ExactTargetParameter object in the command's collection without any prefix. You can use these prefixes in any combination. Named parameters have two main advantages. First, you do not have to care about the order in which parameters are created. Second, a named parameter can appear more than once in the query text, but you have to create only one instance of it in the Parameters collection.

    For example, a simple UPDATE statement with named parameters might look like the following:

    UPDATE Email SET Subject = :subject WHERE Name = :name

    To set parameters for this query, you can use the following code:

    
        using (var connection = new ExactTargetConnection("user=MyCompanyAdmin;password=mypassword;url=https://webservice.s7.exacttarget.com/Service.asmx;")) {
            connection.Open();
    
            ExactTargetCommand cmd = connection.CreateCommand();
            cmd.CommandText = "UPDATE Email SET Subject = :subject WHERE Name = :name";
            cmd.Parameters.Add("subject", DbType.String).Value = "sample subject 1";
            cmd.Parameters.Add("name", DbType.String).Value = "sample name 1";
    
            cmd.ExecuteNonQuery();
        }
    
    
    
        Using connection As New ExactTargetConnection("user=SkyviaDevart;password=sky@devart2014;url=https://webservice.s7.exacttarget.com/Service.asmx;")
            connection.Open()
    
            Dim cmd As ExactTargetCommand = connection.CreateCommand()
            cmd.CommandText = "UPDATE Email SET Subject = :subject WHERE Name = :name"
            cmd.Parameters.Add("subject", DbType.String).Value = "sample subject 1"
            cmd.Parameters.Add("name", DbType.String).Value = "sample name 1"
    
            cmd.ExecuteNonQuery()
        End Using
    
    
    
    

    Using Automatic Parameter Synchronization

    The behavior described above assumes that ExactTargetCommand.ParameterCheck is false (by default). If you set it to true, you enable automatic synchronization of the query text and the ExactTargetCommand.Parameters collection. In this mode, all input parameters are checked for validity, new ones are added if necessary, and redundant parameters are deleted. Thus, you do not have to care about the number of items in the ExactTargetCommand.Parameters collection and can specify only the ones you really need. The synchronization is performed as follows:

    The synchronization takes place when:

    When ExactTargetCommand.ParameterCheck is true, every change of ExactTargetCommand.CommandText or ExactTargetCommand.CommandType deletes all ReturnValue parameters. You have to add them manually each time you change one of these properties.