Database Toolbox User's Guide
  Go to function:
    Search    Help Desk 

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 commands:

If you want to see or copy the commands for this part of the tutorial, or if you want to run the set of commands, 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:
   2.
Assume that the date in the Access Avg_Freight_Cost table is incorrect and instead should be 1/19/98. Type:
   3.
Assign the new date value to the cell array, C, which contains the data you will export.
   4.
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 quotes surround the date instead of the usual single quote.
   5.
Export the data, replacing the record whose Calc_Date is 1/20/98.
   6.
In Microsoft Access, view the Avg_Freight_Cost table to verify the results.


   7.
Close the cursor and disconnect from the database.
Always close a cursor and a connection when you are finished with them to avoid using memory unnecessarily and to ensure there are enough available connections and cursors for other users. Close the cursor before closing the connection.


[ Previous | Help Desk | Next ]