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!