dotConnect for Zoho CRM Documentation
On this page
    Using Parameters
    On this page

    dotConnect for Zoho CRM 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 Zoho CRM, 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 ZohoParameter class. All parameters that take part in query execution constitute a collection that can be accessed through the ZohoCommand.Parameters property.

    Parameters in the query text must correspond to the names of the ZohoParameter instances in the collection. Named parameters are declared using the ':' or '@' prefix followed by the parameter name. Use the name of the ZohoParameter 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 Accounts SET Website = :website WHERE "Account Name" = :name

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

    
        using (var connection = new ZohoConnection("Authentication Type=OAuth;RefreshToken=refresh_token;")) {
            connection.Open();
    
            ZohoCommand cmd = connection.CreateCommand();
            cmd.CommandText = "UPDATE Accounts SET Website = :website WHERE \"Account Name\" = :name";
            cmd.Parameters.Add("website", DbType.String).Value = "www.devart.com";
            cmd.Parameters.Add("name", DbType.String).Value = "sample name 1";
    
            cmd.ExecuteNonQuery();
        }
    
    
    
        Using connection As New ZohoConnection("Authentication Type=OAuth;RefreshToken=refresh_token;")
            connection.Open()
    
            Dim cmd As ZohoCommand = connection.CreateCommand()
            cmd.CommandText = "UPDATE Accounts SET Website = :website WHERE ""Account Name"" = :name"
            cmd.Parameters.Add("website", DbType.String).Value = "www.devart.com"
            cmd.Parameters.Add("name", DbType.String).Value = "sample name 1"
    
            cmd.ExecuteNonQuery()
        End Using
    
    
    
    

    Using Automatic Parameter Synchronization

    The behavior described above assumes that ZohoCommand.ParameterCheck is false (by default). If you set it to true, you enable automatic synchronization of the query text and the ZohoCommand.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 ZohoCommand.Parameters collection and can specify only the ones you really need. The synchronization is performed as follows:

    The synchronization takes place when:

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