How do I use datainsert/fastinsert functions for an Access database?

1 回表示 (過去 30 日間)
L
L 2017 年 1 月 10 日
コメント済み: L 2017 年 1 月 27 日
Hello,
So I've been working on a project for awhile now and through the hiccups, I've finally gotten close to creating the script/function to do what I need. My problem now is that I can't seem to get those functions to work. Below is the command and the error I keep getting.
curs2 = fastinsert(conn,tablename,columns,tabledata);
Error using database.odbc.connection/fastinsert
Too many output arguments.
I've also tried datainsert, but I get the same thing. Anyways, conn is my connection, tablename is the name of the table in the Access database, columns is a cell of the column names in the database (that were extracted from an excel file (excelfile(1,1:end)), and tabledata is the data I wish to store in the Access database (also extracted from an excel file (excelfile(2:end,1:end)).
I've built this script to be used for similar data sets but with varying rows and/or columns. I would greatly appreciate any help as I can't seem to get this data to be easily inserted into the database I've made.
Thank you in advanced!
-L

採用された回答

Ankitha Kollegal Arjun
Ankitha Kollegal Arjun 2017 年 1 月 13 日
The error is likely due to the assignment of fastinsert to curs2. That is not a supported syntax. Instead, try the following to view the database:
fastinsert(conn,tablename,columns,tabledata);
curs = exec(conn,'select * from tablename');
curs = fetch(curs);
curs.Data
  2 件のコメント
L
L 2017 年 1 月 17 日
Hello Ankitha,
Although it seems your recommendation took me a step in the right direction, I ran into another error. See below.
Error using database.odbc.connection/insert (line 247)
ODBC Driver Error: [Microsoft][ODBC Microsoft Access Driver] Undefined function 'Range' in expression.
Error in database.odbc.connection/fastinsert (line 40)
insert( connect,tableName,fieldNames,data );
One of the column names in my table is supposed to be "Range (m)" and I think that it is thinking Range is a function, when it is just one of the columns from the table. My definition of columns and tabledata:
columns = exceldata(1,1:end);
tabledata = exceldata(2:end,1:end);
I think I've read about this somewhere, but I'm not sure how to fix the syntax so it accepts range as just the name of the column. I would be very grateful for any assistance.
Thank you,
L
L
L 2017 年 1 月 27 日
I figured out the problem. I just had to wrap each column name in [] and I did so using a regexprep. Then datainsert worked just fine.
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by