Reference to non-existent field error when showing database data to editbox in gui matlab

조회 수: 1 (최근 30일)
Im getting error when showing database to gui . i do some bill parking program.
field = {'Code','Come in','Come out','Fee'}
exdata = {'ABCD','03:00','04:00',10}
firstly, my program do is hit pushbutton1 to insert database to field 'Code' and 'Come in'. secondly, hit pushbutton2 to update database field 'Come out',and 'Fee' and show all data to gui from Code i type to Code editbox .
My code :
conmysql = database('skripsi_mysql','root','')
sql = ['select * from data where Code =','''',handles.code,''''];
fetch(conmysql,'select *from data')
data = fetch(conmysql,sql);
t1 = datestr(datenum(now),'HH:MM');
t2 = datenum(t1);
t3 = datenum(data.in);
time_diff = t3 - t2;
hours = ceil(time_diff * 24)
fee = hours * 5;
field = {'Come In','Fee'};
databaru = {t1,fee};
tablename = 'data';
whereclause = ['where Code =','''',handles.code,''''];
update(conmysql,tablename,field,databaru,whereclause);
fetch(conmysql,sql);
set(handles.in,'String',data.in)
set(handles.out,'String',data.out)
set(handles.fee,'String',data.fee)
and i got error like this :
Reference to non-existent field 'in'.
Error in skripsi>out_Callback (line 208)
t3 = datenum(data.in);
Have you any suggestion for this problem sir ? Thank a lot before.

답변 (1개)

Brendan Hamm
Brendan Hamm 2016년 9월 14일
You have no field called 'in' contained in the data cursor returned by fetch. You probably want to look into the 'Data' property of cursor as this is where the fetched data is stored.
returnedData = data.Data
I would highly recommend entering into debug more on the lines where you can not figure out what is happening.
  댓글 수: 2
obstac
obstac 2016년 9월 14일
편집: obstac 2016년 9월 14일
do you have any suggestion to change it to make simple or something sir ? thanks for reply . yes i want to use data.in/out to make variable fee
Brendan Hamm
Brendan Hamm 2016년 9월 14일
Your variable data is a cursor object and you cannot add new properties to it.
conmysql = database('skripsi_mysql','root','')
sql = ['select * from data where Code =','''',handles.code,''''];
data = fetch(conmysql,sql);
When you do this the variable data is a cursor, regardless of the query or anything else. A cursor has very specific Properties and one of these is the 'Data' property.
returnedData = data.Data % Here is where the queried data is stored.
But, you try and index into it using
data.in
this happens on the line:
t3 = datenum(data.in);
and you get an error. I suggest you take a look in the debugger (using the link I provide above) as I cannot tell you what the result of your query is, I can only tell you why this error is occurring and where to look to correct it.

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

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by