procedure TForm2.Button1Click(Sender: TObject); var str:string; begin str:=trim(radiogroup3.items[radiogroup3.ItemIndex]); adoquery2.Close; adoquery2.SQL.Clear; adoquery2.SQL.Add('select * from book '); if radiogroup3.ItemIndex=0 then adoquery2.SQL.Add('where bookname like '%'+trim(edit1.Text)+'%'') else adoquery2.SQL.Add('where bookname like '%'+trim(edit1.Text)+'%' and bookdepartment='+s+''); adoquery2.Prepared; adoquery2.Open;
在这里adoquery2.SQL.Add('where bookname like '+''+'%'+trim(edit1.Text)+'%'+'') else adoquery2.SQL.Add('where bookname like '+''+'%'+trim(edit1.Text)+'%'+'' and bookdepartment=''+ s+'' ); ''转义为一个'