User`s guide
7 Functions — Alphabetical List
7-90
conn = database('MySQL','username','pwd');
Display the last rows in inventoryTable before insertion of data.
curs = exec(conn,'select * from inventoryTable');
curs = fetch(curs);
curs.Data
ans =
...
[14] [2000] [19.1000] '2014-10-22 10:52...'
[15] [1200] [20.3000] '2014-10-22 10:52...'
[16] [1400] [34.3000] '1999-12-31 00:00...'
Create cell array of column names for the database table inventoryTable.
colnames = {'productNumber','Quantity','Price','inventoryDate'};
Define the cell array of input data to insert.
data = {50 100 15.50 datestr(now,'yyyy-mm-dd HH:MM:SS')};
Insert the input data into the table inventoryTable using database connection conn.
tablename = 'inventoryTable';
datainsert(conn,tablename,colnames,data)
Display inserted data in inventoryTable.
curs = exec(conn,'select * from inventoryTable');
curs = fetch(curs);
curs.Data
ans =
...
[15] [1200] [20.3000] '2014-10-22 10:52...'
[16] [1400] [34.3000] '1999-12-31 00:00...'
[50] [ 100] [15.5000] '2014-10-22 11:29...'
The last row contains the inserted data.
Close the connection.