How to use sqlwrite

4 次查看(过去 30 天)
Blue
Blue 2021-7-15
回答: Navya Singam 2021-10-28
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);

回答(1 个)

Navya Singam
Navya Singam 2021-10-28
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.

类别

Help CenterFile Exchange 中查找有关 Rubik's Cube 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by