How to use sqlwrite
4 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
回答 (1 件)
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)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!