How to make a GUI that outputs data from SQLdatabase corresponding to the input?

1 次查看(过去 30 天)
So I'm pretty new at this, so I've been having some trouble with this project. Basically, I am given an excel sheet of data, which I imported into sql. Now in my matlab gui, I wanted to have a list box of unique ID numbers (9732 to 9806 to be exact); these numbers correspond to a specific line of data. What I wanted was the user can choose a number from the list and the gui would spit out the data for that exact number in static text boxes. Any recommendations to go about this?

采纳的回答

Geoff Hayes
Geoff Hayes 2017-1-20
maybellene - if you are using GUIDE (and I suppose even if you aren't!) you would need to use the listbox callback function which fires whenever the user selects something from the list box. For a GUIDE-created GUI, you would do
function listbox1_Callback(hObject, eventdata, handles)
listElements = get(hObject,'String'); % cell array of items
selectIdx = get(hObject,'Value'); % the index of the item selected by user
element = listElements{selectIdx}; % the element (id or whatever)
You would then convert element to the appropriate data type (probably an integer) and then build your SQL statement to query your database for the item whose ID is element. With the response, you would then update your static text fields using the handles structure (which has a handle to each text box).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by