Compare value to cell in database

조회 수: 4 (최근 30일)
Han
Han 2018년 3월 11일
댓글: Han 2018년 3월 12일
HI ..
Id and password are int data type in database
I want to check if the id and password entered by user are in database.
Code:
a = get(handles.Id,'String');
b = get(handles.password,'String');
conn = database.ODBCConnection('users','root','root');
x = exec(conn,'select ID from Admin');
y = exec(conn,'select Password from Admin');
x = fetch(x);
y = fetch(y);
x1 = x.Data
y1 = y.Data
L1 = strcmp(a,x1)
L2= strcmp(b,x1)
if L1 == 1 && L2 == 1
track
else
msgbox('Rong ID or Password ! ');
end
I trired to convert x1 and y1 to string
x2 = num2str(x1);
I get this error:
Input to num2str must be numeric.
I know that x1 is cell but I don't know how can I do it !
Can you please help me?

채택된 답변

Walter Roberson
Walter Roberson 2018년 3월 12일
Except for SQLite, it is possible to configure the database as to what datatype is to be returned by fetch (SQLite always returns the same datatype, and that is not the same datatype as the default for other databases.)
I suspect that if you check class(x1) that you will find that it is a 1 x 1 cell array containing a numeric value. Another possibility is that it might be a struct containing the field 'ID' .
  댓글 수: 3
Jos (10584)
Jos (10584) 2018년 3월 12일
Using curly brackets, x1{1} will give you the numeric value inside the cell :)
Han
Han 2018년 3월 12일
Thank you :)

댓글을 달려면 로그인하십시오.

추가 답변 (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