필터 지우기
필터 지우기

How to insert data in Database MS Access

조회 수: 5 (최근 30일)
Jake
Jake 2016년 12월 22일
댓글: David Barry 2016년 12월 23일
Hi MATLAB experts,
What I am trying now is to append data to the end of existing table called 'CashFlows' in MS Access database. I pushed data into the table, using the code below.
colnames = {'Date','IDcode','Inflow','Outflow','Net Money'};
tablename = 'CashFlows';
cash_added =
'12/22/2016' [123] [1000] [-200] [800]
insert(connfof, tablename, colnames, cash_added)
However, by using these above, it doesn't seem working because of 'Net Money' in the colnames even though it is a header.
Thus, I just realized that there should not be any spaces in colnames...
In this situation, do you know what other functions I have to use instead of 'insert' to push/append data since I am not allowed to change the headers (i.e. 'Date','IDcode','Inflow','Outflow','Net Money')???..
Hope I explained the case well.
Thanks for your help in advance.

답변 (1개)

David Barry
David Barry 2016년 12월 22일
I'm not sure about MS Access but with other database you would usually have to deal with fields that contain spaces but either using quotes or brackets around the name, e.g.
colnames = {'Date','IDcode','Inflow','Outflow','''Net Money'''};
or
colnames = {'Date','IDcode','Inflow','Outflow','[Net Money]'};
What's the error message you get back by the way? This might help us to debug.
  댓글 수: 2
Jake
Jake 2016년 12월 22일
Hi I tried both, but got this message:
Error using database/insert (line 189) [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
David Barry
David Barry 2016년 12월 23일
Have you tried datainsert and fastinsert instead of insert?

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

카테고리

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