How to delete from MS Access database using GUI interface

1 view (last 30 days)
I prepared the following table with MS Access called 'Table1'. The table is shown below: ID Harzards Location Magnitude Casualties Aids DeathRate 8 1 123 345 321 567 789 9 2 125 675 234 567 123 10 3 123 45 56 23 45 11 4 65 78 34 12 45 12 1 123 345 321 567 789 13 2 125 675 234 567 123 14 3 123 45 56 23 45 15 4 65 78 34 12 45
I used the following code under the GUI interface pushbutton and I received the following error:
CODE: conn = database('grace', ' ',' '); ping(conn); exec(conn, 'DELETE Harzards,Location,Magnitude,Casualties,Aids, DeathRate FROM Table1 {WHERE ID = sprintf(''%f', handles.edit28'')});
ERROR: Error in ==>retrieve2withD>pushbutton4_Callback at 418 exec(conn, 'DELETE Harzards,Location,Magnitude,Casualties,Aids, DeathRate FROM Table1 {WHERE ID = sprintf(''%f', handles.edit28'')});
handles.edit28 holds the value of the ID I intend to delete.
Please, help me out. How do I delete each row in the database table? Also, if I want to import each column in the table, what code do I use? Thank you so much, Oleg, for answering my question yesterday.

Answers (1)

Oleg Komarov
Oleg Komarov on 26 Jul 2011
exec(conn, ['DELETE FROM Table1 WHERE ID =' sprintf('%f', handles.edit28)]);
  • You cannot DELETE some columns and others no, you delete the entire record for which a WHERE clause is verified.
  • The sprintf shuld be a matlab command and not a string.
  1 Comment
hoang
hoang on 2 May 2013
hi okemini and oleg, would you mind to give me some help, i want to delete a row in table database in MS ACCESS via a ODBC with matlab, i used exec(connA, ['DELETE FROM inputtb WHERE Barcode =' sprintf('%s', idbc)])
idbc holds the value of the row i intend to delete. i tried but it doesn't work.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!