I am stuck with inserting data into my MS Access Database. I already converted the data into cell array but it still returns me the error indicating that I am inputting the wrong data type.

1 次查看(过去 30 天)
C =
'SGX 8873 K'
>> iscell(C)
ans =
1
>> datainsert(conn,'VehicleLocation','col2','C')
Error using database/datainsert (line 58)
Input data must be a cell array or numeric matrix.
Been stuck on inserting the data into the database for quite some time now. The input data 'C' is already verified as cell array by the command iscell(C). Anybody got any idea what am I doing wrongly? Thanks.
  3 个评论
Walter Roberson
Walter Roberson 2015-5-20
Umakant, examine the below:
>> 'ABC'
ans =
ABC
>> {'ABC'}
ans =
'ABC'
When you see a string with quotes around it and indented, that is indicating a cell array containing the string; if it were a plain string then it would be displayed without the quote marks or indentation.

请先登录,再进行评论。

回答(3 个)

the cyclist
the cyclist 2015-5-20
编辑:the cyclist 2015-5-20
Guessing you want to remove the quotes from around C in the datainsert statement. You are trying to insert the single character 'C', rather than your variable C.
  1 个评论
Tan Jun Hao
Tan Jun Hao 2015-5-20
编辑:Walter Roberson 2015-5-20
C =
'SGX 8873 K'
>> iscell(C)
ans =
1
>> datainsert(conn,'VehicleLocation','col2',C)
Cell contents reference from a non-cell array object.
Error in database/datainsert (line 72)
insertField = [ insertField fieldNames{i}]; %#ok
Thanks for the prompt reply. However, MATLAB still indicates that I am not inputting a cell array data. Any idea how to solve this problem?

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2015-5-20
datainsert(conn,'VehicleLocation', {'col2'}, C)
The column names must be cell array of string.
  2 个评论
Tan Jun Hao
Tan Jun Hao 2015-5-20
datainsert(conn,'VehicleLocation',{'col2'},C)
Error using database/datainsert (line 106) [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
Tried doing it before but couldn't work.

请先登录,再进行评论。


Thomas Koelen
Thomas Koelen 2015-5-20
Are you sure you already created a database?
  5 个评论
Tan Jun Hao
Tan Jun Hao 2015-5-21
Alright thanks! That solved my problem. But now I am currently stuck at inserting multiple columns of data in one instance. Any ideas?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by