How to update database with whereclause using variable as ID and launching it from a GUI
2 次查看(过去 30 天)
显示 更早的评论
[EDIT: 20110725 09:37 CDT - reformat - WDR]
I prepared a table called 'Table1' with MS Access as shown below
ID Harzards Location Magnitude Casualties Aids DeathRate
1 123 345 321 567 789 456
2 125 675 234 567 123 456
3 123 45 56 23 45 569
4 65 78 34 12 45 579
8 1 123 345 321 567 789
9 2 125 675 234 567 123
10 3 123 45 56 23 345
I used the following code under the pushbutton callback function to launch the update and I had the following error
code:
colnames = {'Harzards','Location','Magnitude','Casualties',Áids','DeathRate'};
conn = database('grace',' ',' ');
set(conn, 'ÁutoCommit', 'on');
get(conn, 'ÁutoCommit');
update(conn, 'Table1', colnames,{handles.edit1,handles.edit2,handles.edit3,handles.edit4,handles.edit5,handles.edit16}, {'where ID = handles.edit28'});
The values to all the handles are specified on the GUI interface
Error generated:
Error in ==> retrieve2withD>pushbutton3_callback at 383
update(conn, 'Table1', colnames,{handles.edit1,handles.edit2,handles.edit3,handles.edit4,handles.edit5,handles.edit16}, {'where ID = handles.edit28'});
retrieve2withD is the M-file name for the GUI interface.
Please help me out, how do I replace data in the database. Thanks.
1 个评论
Oleg Komarov
2011-7-25
PLease format the code: http://www.mathworks.com/matlabcentral/answers/7885-tutorial-how-to-format-your-question
采纳的回答
Oleg Komarov
2011-7-25
You cannot supply the where clause in that way.
You are saying update the columns indicated in colnames with the values contained in the cell array of handle.edit# where the ID = 'handles.edit28', but you want to retrieve the value of handles.edit28.
So, if handles.edit28 is a single values, then:
update(...,['where ID = ' sprintf('%f',handles.edit28)])
or if multiple values:
update(...,['where ID in(' sprintf('%f',handles.edit28(1)) sprintf(',%f',handles.edit28(1)) ')'])
The third method is listed in the documentation and it poses a specific where clause column by column.
2 个评论
MEP
2023-8-10
This work also for me but when I want compare an array of values for example if I have not handles.edit28 but an array of elements?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Hamamatsu Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!