Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Ankitha Kollegal Arjun
Ankitha Kollegal Arjun el 13 de En. de 2017
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 comentarios
L
L el 17 de En. de 2017
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 el 27 de En. de 2017
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!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by