Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble to pass paramts in SQL 1

Status
Not open for further replies.

scubaman

Programmer
Nov 10, 2000
6
BR
Hello,


I have a button when click
do this

procedure TLogin.Button1Click(Sender: TObject);
var
strSqlLog: String;
begin
strSqlLog:= 'Select * from usuario,perfil WHERE usuario.nivel = perfil.id';
strSqlLog:= strSqlLog + 'AND fantasia = ' + #39 + (valorNome.text) + #39 ;
strSqlLog:= strSqlLog + 'AND senha = ' + #39 + (valorNome.text) + #39 ;

menuPrin.QueryLogin.Close;
menuPrin.QueryLogin.SQL.Clear;
menuPrin.QueryLogin.sql.Add(strSqlLog);
menuPrin.QueryLogin.Open;

the problem is... the line

strSqlLog:= strSqlLog + 'AND fantasia = ' + #39 + (valorNome.text) + #39 ;
strSqlLog:= strSqlLog + 'AND senha = ' + #39 + (valorNome.text) + #39 ;

It told invalid statement....

I don't know what's wrong....

Please help me

Thanks a Lot

Luciano Marques
 
Try
Code:
strSqlLog:= strSqlLog + 'AND fantasia = ' + QuotedStr(valorNome.text);
HTH

--- markus
 
Yea you are missing a space between perfil.id and AND.

When I write SQL statements and get errors like that, it can be helpful to debug the program and hover over the strSqlLog variable after it has been fully populated. Then you can verify with your own eyes that the SQL statement has the spaces and quotation marks in the right places.

If you are using s SQL server database and there is a problem I often use the query analyser to try and fix bad SQL statements, sometimes the error messages are more meaningful.

Andrew

"If it is stupid, but it works, then it isn't stupid"
 
Hello,

That's it

I'm correct using QuotedStr

And the problem the space in the sentence
using "AND" was necessery a space still


Thank's a lot for
markus and Andrew


Best regards

Luciano Marques
 
You could also write the following:

strSqlLog:= 'Select * from usuario,perfil WHERE usuario.nivel = perfil.id';
strSqlLog:= strSqlLog + 'AND fantasia = ' + #39 + (valorNome.text) + #39 ;
strSqlLog:= strSqlLog + 'AND senha = ' + #39 + (valorNome.text) + #39 ;

like this

strSqlLog := 'SELECT * FROM USUARIO, PERFIL WHERE ' +
USUARIO.NIVEL = PERFIL.ID AND FANTASIA = ' +
QUOTEDSTR(VALORNOME.TEXT) + ' AND SENHA = ' +
QUOTEDSTR(VALORNOME.TEXT);

By using the + at the end of each line, you don't have to keep repeating the strSqlLog = strSqlLog +


Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top