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