Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to delete from MS Access database using GUI interface

Asked by Ekemini Stephen on 26 Jul 2011

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.

0 Comments

Ekemini Stephen

Products

1 Answer

Answer by 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 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.

Oleg Komarov

Contact us