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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IBquery Problem

Status
Not open for further replies.

namyboj

Technical User
Jun 8, 2006
3
0
0
GB
New user to SQLQuery

I have a problem, here is a simplified code on a buttons on-click event

query1.Close;
query1.SQL.Clear;
query1.SQL.Add('SELECT EMP_NO, FIRST_NAME, FULL_NAME, LAST_NAME, SALARY' );
query1.SQL.Add('FROM EMPLOYEE');
query1.sql.Add('WHERE FIRST_NAME='+edit1.Text);
query1.Open;

I have an error on run when you enter text in an edit box.
I know the SQL statement is correct as the DBGrid shows the result at design time. the problem has to do with the parameters section.

How do I use the parameters in the above code.

Ive tried everything in the help section but nothing.

Sorry and thanks for any help.


 
Add quotes. Like this:
Code:
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('SELECT EMP_NO, FIRST_NAME, FULL_NAME, LAST_NAME, SALARY' );
query1.SQL.Add('FROM EMPLOYEE');
query1.sql.Add('WHERE FIRST_NAME=' + QuoteStr(edit1.Text));
//OR
//query1.sql.Add('WHERE FIRST_NAME="' + edit1.Text + '"');
query1.Open;


Roo
Delphi Rules!
 
Sorry tried the new code still the same error.
Think problem has to do with setting parameters for the text thats in the edit box, I think.

Thanks for that
 
use the code of roo0047
but write QuotedStr(Edit1.text) instead
of QuoteStr .
if you still have the same thing
write us the error message inorder to
better understand it.
Best wishes
 
Sorry still not working.
Error message "Column ? not found" where ? is the name from the edit box.

I think I have to declare the param and send a value to it so that it can be integrated into the sql statement.
Tried this but still no luck

query1.param[0].asstring:=edit1.text;
and this
query1.parambyname('FirstName').asstring:=edit1.text;

then integrating the param as follows

query1.Close;
query1.SQL.Clear;
query1.SQL.Add('SELECT EMP_NO, FIRST_NAME, FULL_NAME, LAST_NAME, SALARY' );
query1.SQL.Add('FROM EMPLOYEE');
query1.sql.Add('WHERE FIRST_NAME=:FirstName');
query1.parambyname('FirstName').asstring:=edit1.text;
query1.open;


If I move the above 2 lines of code the give varying error messages. Do i have to declare the Param as a var
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top