Replacing Existing Database Data with Exported Data

This example updates the Month field that you previously imported (Exporting Data to New Record in Database) into the yearlySales table of the dbtoolboxdemo data source using the following Database Toolbox™ functions:

For details about these functions, see matlab\toolbox\database\dbdemos\dbupdatedemo.m.

  1. Change the month in yearlySales table from March to March2010. Assign the new month value to the newdata cell array.

    colnames = {'Month'};
    newdata = {'March2010'}
    newdata =
        'March2010'
    
  2. Specify the record to update in the database by defining a SQL where statement and assigning it to the variable whereclause. The record to update is the record whose Month is March. Because the date string is within a string, it is embedded within two single quotation marks rather than one.

    whereclause = 'where Month = ''March'''
    whereclause =
    	where Month = 'March'
    
  3. Export the data, replacing the record whose Month is March.

    update(conn,'yearlySales',colnames,newdata,whereclause)
  4. In Microsoft® Access™, view the yearlySales table to verify the results.

  5. Disconnect from the database.

    close(conn);
    
Was this topic helpful?