Search code examples
databasematlabms-accessdata-export

Matlab to Microsoft Access Database 2010 Date and Time


how to input the date and time to MS access by hitting a pushbutton at matlab figure?

enter image description here

my code for the date and time checkbox is:

m=1;
while m==1
m=get(hObject,'value');
txt=datestr(now);
set(handles.text7,'string',txt);
pause(1);
end

That code is located at a checkbox and date&time appears at static text. What I wanted to do is insert a pushbutton and whenever I will hit the pushbutton, It will be sent to the database table as an input but I don't know how to sync MS access to MatLab. Please help me because I'm very troubled right now :( Thank you in advance!


Solution

  • I finally made the connection of matlab and ms access. Here's the tutorial on how to configure the connection first.

    After successfully making a connection, I used this code on a callback.

    conn = database('databasename','username','password');
    dbpath = 'C:\Users\______.mdb'; %insert database path
    tableName = 'datetime'; %insert tablename here in MSAccess
    colname = {'column1'} %column of your tables in MsAccess
    date = datestr(now); %the string of date and time
    coldata = {date}
    insert(conn,tableName,colname,coldata); %will insert the data to the database.
    close(conn);