Azzera filtri
Azzera filtri

How to update database with whereclause using variable as ID and launching it from a GUI

3 visualizzazioni (ultimi 30 giorni)
[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.

Risposta accettata

Oleg Komarov
Oleg Komarov il 25 Lug 2011
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.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by