unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, ExtCtrls, DBCtrls, DBTables, StdCtrls;type
  TForm1 = class(TForm)
    Query1: TQuery;
    DBNavigator1: TDBNavigator;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    Query1Name: TStringField;
    Query1Sex: TStringField;
    Query1BirthDay: TDateTimeField;
    Query1Job: TStringField;
    Query1Dept: TStringField;
    Query1Salary: TStringField;
    procedure RadioGroup1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
  published
    property Text;
    { Public declarations }
  end;var
  Form1: TForm1;
  state:integer;
implementation{$R *.dfm}procedure TForm1.RadioGroup1Click(Sender: TObject);begin
  edit1.Clear;
  case   RadioGroup1.ItemIndex of
0:    begin
        Label1.caption:='按姓名查询:';
        Label1.Refresh;
        Label2.Caption:='请输入姓名:';
        Label2.Refresh;
        state:=0;
      end;
1:    begin
       Label1.Caption:='按部门查询:';
       Label1.Refresh;
       Label2.Caption:='请输入部门:';
       Label2.Refresh;
       state:=1;
      end;
    end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
  Query1.Open;
  State:=0;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
     Query1.SQL.Clear;
     if state=0 then
     begin
     Query1.SQL.Add('select* from Employee as s where s."姓名"=:Name');
     Query1.Prepare;
     Query1.Params[0].AsString:=edit1.Text;
     end;     if state=1 then
     begin
     Query1.SQL.Add('select* from Employee as s where s."部门"=:Dept');
     Query1.Prepare;
     Query1.Params[0].AsString:=edit1.Text;
     end;
     Query1.Open;
end;end.

解决方案 »

  1.   

    Query1.SQL.Add('select* from Employee as s where s.姓名=:Name');
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
         Query1.Close ; //
         Query1.SQL.Clear;
         if state=0 then
         begin
         Query1.SQL.Add('select* from Employee as s where s."姓名"=:Name');
         Query1.Prepare;
         Query1.Params[0].AsString:=edit1.Text;
         end;     if state=1 then
         begin
         Query1.SQL.Add('select* from Employee as s where s."部门"=:Dept');
         Query1.Prepare;
         Query1.Params[0].AsString:=edit1.Text;
         end;
         Query1.Open;
    end;end.
      

  3.   

    抱歉, 不 Close 竟然可以,应该是yzykjh(多米诺骨牌)的对 :)