How to use sqlwrite

3 views (last 30 days)
Blue
Blue on 15 Jul 2021
Answered: Navya Singam on 28 Oct 2021
Hi,
I am running into some problems with sqlwrite. I am trying to duplicate the example found here (https://www.mathworks.com/help/database/ug/database.odbc.connection.sqlwrite.html#namevaluepairarguments) where I want to add one row of data to an existing table.
However when I use sqlwrite I get the following error message: Error using database.odbc.connection/sqlwrite (line 85) Multiple table entry found for 'database_table'. Must provide 'Catalog' and 'Schema' values.
I have read the documentation but Im still stuck. I dont understand what the problem is nor how to fix it. Thoughts / ideas ?
Thank you,
conn = database('tt', 'username', 'password');
productNumber = [13, 14, 15]';
stockNumber = [47082, 51010, 89975]';
supplierNumber = [1012, 1011, 1011]';
unitCost = [17, 19, 20]';
productDescription = {'Pancakes', 'Shawl', 'Snacks'}';
database_table = table( productNumber, stockNumber, supplierNumber, unitCost, productDescription);
data = table(30, 500000, 1000, 25, "Rubik's Cube", ...
'VariableNames',{'productNumber' 'stockNumber' ...
'supplierNumber' 'unitCost' 'productDescription'});
sqlwrite(conn, database_table, data);
close(conn);

Answers (1)

Navya Singam
Navya Singam on 28 Oct 2021
Hi Blue,
The error in the code is beacuse of the following lines in your code
database_table = table( productNumber, stockNumber, supplierNumber, unitCost, productDescription);
sqlwrite(conn, database_table, data);
"sqlwrite" function expects second argument to be name of the database table.
This line of code creates a MATLAB table.
database_table = table( productNumber, stockNumber, supplierNumber, unitCost, productDescription);
The code works fine by replacing second argument in "sqlwrite" to any database table name such as 'productTable'
sqlwrite(conn,'productTable',data)
Refere to the sqlwrite documentation for more information on input arguments of sqlwrite.

Categories

Find more on Rubik's Cube in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!