UpdateData()

Updates data in a data extension, and returns the number of rows updated.

You can use this function in CloudPages, landing pages, microsites, and SMS messages in MobileConnect. To update rows in a data extension in an email, use the UpdateDE() function.

The UpdateData() function has six parameters:

  • dataExt (string): Required. The name of the data extension that contains the data to update.
  • columnValuePairs (number): Required. The number of column and value pairs for the function to match against.
  • searchColumnName1 (string): Required. The name of a column to search for the data to update.
  • searchValue1 (string): Required. The value that the function uses to determine which row to update. You can specify multiple column and value pairs to match against.
  • columnToUpdate1 (string): Required. The column that contains the data to update.
  • updatedValue1 (string): Required. The data to update in the specified column. You can specify multiple column and value pairs to update.

To use the function, first pass it the name of the data extension that contains the data you want to update. Next, pass it the name of the column to search to find the row that you want to update, and the value that identifies the row to update. Finally, pass it the name of the column that you want to update the data in, and the value that you want to update.

In this example, a data extension called "Flights" contains the data in this table.

FlightIdOriginDestPricePerBagSurcharge
1INDNYC100
2INDLAX200
3INDSEA50025
4ORDSEA52510
5ORDLAX400
6SEASAN300
7SEAATL10
8ATLAUS35010
9STLKCA5
10INDATL125

To update the Price value for FlightId 10, use this function.

The function returns 1, indicating that it updated one row. The data extension now contains this data.

FlightIdOriginDestPricePerBagSurcharge
1INDNYC100
2INDLAX200
3INDSEA50025
4ORDSEA52510
5ORDLAX400
6SEASAN300
7SEAATL10
8ATLAUS35010
9STLKCA5
10INDATL225

You can use the UpdateData() function to update more than one column in a single row in one operation. To update multiple columns, you must provide one set of search criteria for each column that you want to update.

This example uses a data extension called "Flights2" that contains the data in this table.

FlightIdOriginDestPricePerBagSurcharge
1INDNYC100
2INDLAX200
3INDSEA50025

Use this code to update the Dest, Price, and PerBagSurcharge fields for FlightId 1.

The function returns 1, indicating that it updated one row. The data extension now contains this data.

FlightIdOriginDestPricePerBagSurcharge
1INDJFK7510
2INDLAX200
3INDSEA50025

If you receive errors or notice incomplete updates when you use this function, consider these factors:

  • If you specify a value for the columnValuePairs parameter that doesn’t agree with the number of matching criteria in the function, the function returns an exception.
  • If you specify a column name for the searchColumnName parameter that doesn’t exist in the specified data extension, the function produces an exception.
  • If you specify a value for the searchValue parameter that isn’t found in the specified column, the function doesn’t update any data and returns 0.
  • If you specify a value for the updatedValue parameter that’s of a different data type than the column that you specified in the columnToUpdate parameter, the function doesn’t update any data and returns 0. For example, if you pass a numeric value, but the column contains string data, the function doesn’t update the data.
  • If the number of search parameters (searchColumnName and searchValue) doesn’t equal the number of update parameters (columnToUpdate and updatedValue), the function updates the columns for which you have provided search parameters. For example, if you provide two search parameters and three update parameters, the function only implements the first two update parameters. You can repeat the same update parameters multiple times if necessary.