ADO.NET Provider for Marketo

Build 25.0.9434

UPSERT Statements

An UPSERT statement updates an existing record or creates a new record if an existing record is not identified.

UPSERT Syntax

The UPSERT syntax is the same as for INSERT. Marketo uses the input provided in the VALUES clause to determine whether the record already exists. If the record does not exist, all columns required to insert the record must be specified. See Data Model for any table-specific information.

UPSERT INTO <table_name> 
( <column_reference> [ , ... ] )
VALUES 
( { <expression> | NULL } [ , ... ] ) 
  

<expression> ::=
  | @ <parameter> 
  | ?
  | <literal>

You can use the ExecuteNonQuery method to issue data manipulation commands and retrieve the rows affected, as shown in the following example:

C#

String connectionString = "URL=https://MyMarketoURL.mktorest.com/;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;";
int rowsAffected;
using (MarketoConnection connection = new MarketoConnection(connectionString)) {
  MarketoCommand cmd = new MarketoCommand("UPSERT INTO Leads (Email) VALUES ('John')", connection);
  rowsAffected = cmd.ExecuteNonQuery();
}

VB.NET

Dim connectionString As [String] = "URL=https://MyMarketoURL.mktorest.com/;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;"
Dim rowsAffected As [Integer]
Using connection As New MarketoConnection(connectionString)
  Dim cmd As New MarketoCommand("UPSERT INTO Leads (Email) VALUES ('John')", connection)
  rowsAffected = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2025 CData Software, Inc. - All rights reserved.
Build 25.0.9434