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

WHERE and SQL?

Status
Not open for further replies.

tag141

Technical User
Oct 4, 2003
119
AU
I am trying to set up a simple grid and allow a user to search for a particular surname from a db. I have a datasource, SQLand my DBgrid. If I press the button without a WHERE statement it selects and displays all the surnames. If I try and put a edit box in and make it select a certain name , it always throws an error stating too few parameters.

My code is

Code:
procedure TForm1.Button1Click(Sender: TObject);
var s : string;

begin
      s := 'select * from tblMyTable where SURNAME = ' + (Edit1.Text);
      Query1.Active := false;
      Query1.Sql.Clear;
      Query1.Sql.Text := s;
      Query1.ExecSQL;
      Query1.Active := true;
end;

I have searched high and low on the internet to try and find the answer but to no avail. Have any of you guys an idea to why this doesn't work? TIA.
 
Sorry guys. Sods law isn't it. Just as I post for help it arrives. The problem was this:
Code:
s := 'select * from tblMyTable where SURNAME = ' + (Edit1.Text);

didn't work but this does

Code:
s := 'select * from tblMyTable where SURNAME = ' + QuotedStr(Edit1.Text);

and it worked perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top