function with single-string argument, querying sql database

2 vues (au cours des 30 derniers jours)
Isma
Isma le 31 Août 2015
Commenté : Walter Roberson le 31 Août 2015
Hi everyone
Please see below my codes aiming at creating a function which queries data from my database:
function x=getsqldata(var);
Set preferences with setdbprefs.
setdbprefs('DataReturnFormat', 'cellarray');
setdbprefs('NullNumberRead', 'NaN');
setdbprefs('NullStringRead', 'null');
% Set maximum time allowed for establishing a connection.
timeout=logintimeout(10);
%Make connection to database. Note that the password has been omitted.
%Using ODBC driver.
conn = database('odbccalc', 'xx', 'xx');
% Check the database status.
ping(conn);
%Read data from database.
var;
curs = exec(conn, ['SELECT d.ISN , d.Date, d.Px_last FROM tblData d WHERE d.ISN=''',var,'''']);
curs = fetch(curs);
close(curs);
%Assign data to output variable
x = curs.Data;
%Close database connection.
close(conn);
%Clear variables
clear curs conn
While running the function from the command window, I end up with:
getsqldata('CAIXUSD');
Undefined function 'Set' for input arguments of type 'char'.
Thus I wonder if someone could assist. _ In a nutshell, how to make a string variable a valid argument for this function_?
Thanks in advance
ps: the query statements works, I have tested already.
  1 commentaire
Walter Roberson
Walter Roberson le 31 Août 2015
Which line is it reporting the error is occurring on?

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by