MATLAB Answers

0

How to display an sql data Table in a uitable

Asked by Oussama Louati on 21 Nov 2018
Latest activity Commented on by Kojiro Saito on 30 Nov 2018
Hallo every one
How to Upload/ Display a an SQL data Table in a uitable,
Thank you in advance.

  0 Comments

Sign in to comment.

2 Answers

Answer by Kojiro Saito on 27 Nov 2018
 Accepted Answer

From R2018a, we can display table array data in uitable.
The following is an example of reading data from PostgreSQL and show it in uitable.
%% Access to database
conn = database('db_name','usename', 'password', ...
'Vendor','PostgreSQL', ...
'Server','localhost','PortNumber',5432);
tableName = 'table_name';
% Read data from SQL
data = sqlread(conn, tableName);
%% plot in uitable
f = uifigure;
uit = uitable(f, 'Data', data);

  4 Comments

Show 1 older comment
Does it mean selected cells are changable by clicking checkboxes?
After displaying the Table, I want the user to be able to select lines from this table,
I want than later to do something with the selected lines
uitable has a property CellSelectionCallback, and by using this, selected lines can be caught up.
Here is an example of do something from selected lines (app.data and app.selected are properties added in AppDesigner)
app.UITable.CellSelectionCallback = {@selectedChange, app};
function selectedChange(src, eve, app)
% Get selected lines
app.selected = eve.Indices(:, 1);
% Extract only selected lines from original data
selectedData = app.data(app.selected, :);
% Do something on selected lines
% for example,
% m = mean(selectedData);
end

Sign in to comment.


Answer by Oussama Louati on 27 Nov 2018

Thank you very much Kojiro,
This Problem is solved and I'm facing a new one,
how to select Cells (lines) from the Table using Check Box ? ,
Thank you in advance.

  0 Comments

Sign in to comment.