Database Toolbox    

Exporting Data from MATLAB, Replacing Existing Data in a Database

In this part of the tutorial, you export data from MATLAB to a database, updating existing data in the database. Specifically, you update the data you previously imported into the Avg_Freight_Cost table.

You use these Database Toolbox functions:

If you want to see or copy the functions for this part of the tutorial, or if you want to run the set of functions, use the M-file matlab\toolbox\database\dbdemos\dbupdatedemo.m.

  1. If you are continuing directly from the previous part of the tutorial, skip this step. Otherwise, type the following

    MATLAB returns

  1. Assume that the date in the Avg_Freight_Cost table is incorrect and instead should be 1/19/98. Type
  2. Assign the new date value to the cell array, exdata, which contains the data you will export. Type

    MATLAB returns

  1. Identify the record to be updated in the database. To do so, define an SQL where statement and assign it to the variable whereclause. The record to be updated is the record that has 1/20/98 for the Calc_Date.

    Because the date string is within a string, two single quotation marks surround the date instead of the usual single quotation mark. MATLAB returns

  1. Export the data, replacing the record whose Calc_Date is 1/20/98.
  2. In Microsoft Access, view the Avg_Freight_Cost table to verify the results.

  3. Disconnect from the database.

    Always close a connection when you are finished with it to avoid using memory unnecessarily and to ensure there are enough available connections for other users.


 Exporting Data from MATLAB to a New Record in a Database Exporting Multiple Records from MATLAB