Database Toolbox Previous page   Next Page

Replacing Existing Data in a Database from MATLAB

In this example, you update existing data in the database with exported data from MATLAB. Specifically, you update the date you previously imported into the Avg_Freight_Cost table.

You learn to use these Database Toolbox functions:

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

  1. If you are continuing directly from the previous example (Exporting Data from MATLAB to a New Record in a Database), skip this step. Otherwise, type
  1. MATLAB returns

  1. Assume that the date in the Avg_Freight_Cost table is incorrect and instead should be 19-Jan-2002. Type
  2. Assign the new date value to the cell array, newdata, which contains the data you will export. Type
  1. 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 20-Jan-2002 for the Calc_Date.
  1. Because the date string is within a string, two single quotation marks surround the date instead of just a single quotation mark. MATLAB returns

    For more information about working with strings in MATLAB, see Characters and Strings in the MATLAB Programming documentation.

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

  3. Close the cursor and disconnect from the database.
  1. 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.


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

© 1994-2005 The MathWorks, Inc.