Hello!!
I have tried many ways/tutorials on how to export data from MATLAB to Ms Access, but so far, I haven't fully succeed. I could export all my dataset into 1 column instead of 1 row.
Could you guys please help me??
Thanks in advance.
Here's my code:
colnames - cell array with Column Names <1 x 44>
data - cell array with data set to export to Ms Access <15 x 44>
handles.DB.con - Database connection object.;
datainsert(handles.DB.con,'databaseTable', colnames, data);
error:
Error using database/datainsert (line 104)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

댓글 수: 5

Walter Roberson
Walter Roberson 2013년 10월 14일
Complete speculation: perhaps handles.DB.con is not a valid connection at that time. Perhaps it is [] the empty array; perhaps the connection has not been appropriately opened after it was configured.
Friedrich
Friedrich 2013년 10월 14일
@Walter: thats unlikely. In that case you would get an error telling you undefined function datainsert for input or type struct.
The error comes from the driver directly. Are you sure all those columns exist in your database? AFAIK the insert function gives a better error message. Maybe try insert to see if you get a better error.
Well, the connection is okay. I get no error message.
Instance: ''
UserName: ''
Driver: 'sun.jdbc.odbc.JdbcOdbcDriver'
URL: [1x130 char]
Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
Message: []
Handle: [1x1 sun.jdbc.odbc.JdbcOdbcConnection]
TimeOut: 0
AutoCommit: 'on'
Type: 'Database Object'
If I try Insert function I get this error:
insert(handles.DB.con,'databaseTable', colnames, data);
ERROR:
[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
all columns exist in my DB as I copied them 1 by 1, just to make sure! :)
Any ideas??
Thank you very much!!!!
I assume it's related to a column name. Maybe one contains a reserved word. Can you post all the columnnames here? The easiest would be
celldisp(colnames)
BSantos
BSantos 2013년 10월 14일
What kind of names are reserved? Could a column named "Date" be a problem??

댓글을 달려면 로그인하십시오.

 채택된 답변

Friedrich
Friedrich 2013년 10월 14일
편집: Friedrich 2013년 10월 14일

0 개 추천

Hi,
yes DATE is a reserved keyword. For a full list see here. You can stil use it but you should escape any column names which are also keywords or functions. In MS Access it should be [] brackets. So instead of 'Date' use '[Date]' as column name.

댓글 수: 3

BSantos
BSantos 2013년 10월 14일
I still get the same errors even if I change the Column Name..
Friedrich
Friedrich 2013년 10월 14일
편집: Friedrich 2013년 10월 14일
Maybe there are others? The error is given from the driver directly and not from MATLAB. It must be something with the syntax which MATLAB uses to run the SQL command internally.
Maybe start with a dummy database containing one column name and see if it works. if so add a 2nd column and try again. This will lead to the column name which causes the troubles here.
BSantos
BSantos 2013년 10월 14일
So, I just tried with INSERT function, and now all is okay!
THANK YOU very much!!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2013년 10월 14일

댓글:

2013년 10월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by