我想实现这样一个功能,就是能够修改dbgrid里所获取query控件查询到的数据。我将query控件里的requestlive设为true,这样在第一张表单里就能够对dbgrid进行修改操作。但是在第二个表单里面想进行查询时就出现了问题,说是“invalid use of key word.token:year(b_time)=?”,然后我把requestlive属性改为false后又可以查询了。另:这两个表单都是对同一张数据表进行操作的

解决方案 »

  1.   

    附:第二张表单的查询代码
    begin
    if (edit1.text<>'') and (combobox2.text<>'') and (combobox1.text<>'')
    then
    begin
    zhuanli.qzong.close;
    zhuanli.qzong.sql.clear;
    s:='select * from zong where year(b_time)=:m4 and month(b_time)=:m3 and plant=:m2';
    zhuanli.qzong.sql.text:=s;
    zhuanli.qzong.parambyname('m2').asstring:=combobox1.text;
    zhuanli.qzong.parambyname('m4').value:=strtoint(edit1.text);
    zhuanli.qzong.parambyname('m3').value:=strtoint(combobox2.text);
    zhuanli.qzong.open;
    end
    else if (edit1.text<>'') and (combobox1.text<>'')
    then
    begin
    zhuanli.qzong.close;
    zhuanli.qzong.sql.clear;
    s:='select * from zong where year(b_time)=:m4 and plant=:m2';
    zhuanli.qzong.sql.text:=s;
    zhuanli.qzong.parambyname('m4').value:=strtoint(edit1.text);
    zhuanli.qzong.parambyname('m2').asstring:=combobox1.text;
    zhuanli.qzong.open;
    end
    else if (edit1.text<>'') and (combobox2.text<>'')
    then
    begin
    zhuanli.qzong.close;
    zhuanli.qzong.sql.clear;
    s:='select * from zong where year(b_time)=:m4 and month(b_time)=:m3';
    zhuanli.qzong.sql.text:=s;
    zhuanli.qzong.parambyname('m4').value:=strtoint(edit1.text);
    zhuanli.qzong.parambyname('m3').value:=strtoint(combobox2.text);
    zhuanli.qzong.open;
    end
    else if edit1.text<>''
    then
    begin
    zhuanli.qzong.close;
    zhuanli.qzong.sql.clear;
    s:='select * from zong where year(b_time)=:m4';
    zhuanli.qzong.sql.text:=s;
    zhuanli.qzong.parambyname('m4').value:=strtoint(edit1.text);
    zhuanli.qzong.open;
    end;
    end;
      

  2.   

    请看这里:unit manage;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Mask, DBCtrls, ExtCtrls, Db, DBTables, Grids, DBGrids;type
      Tmana_Form = class(TForm)
        GroupBox1: TGroupBox;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        ComboBox1: TComboBox;
        ComboBox3: TComboBox;
        ComboBox4: TComboBox;
        Button1: TButton;
        Button2: TButton;
        DBGrid1: TDBGrid;
        ComboBox2: TComboBox;
        Button3: TButton;
        Button4: TButton;
        Label5: TLabel;
        Label6: TLabel;
        Edit1: TEdit;
        ComboBox5: TComboBox;
        procedure Button1Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      mana_Form: Tmana_Form;implementation
     uses mydata;
    {$R *.DFM}procedure Tmana_Form.Button1Click(Sender: TObject);
    var s:string;
        s1:string;
        s2:string;
    begin
    if
    (combobox1.text<>'') and (combobox2.text<>'') and (combobox3.text<>'') then
    begin
    zhuanli.qzong.close;
    zhuanli.qzong.sql.clear;
    s:='select * from zong where p_type=:n1 and year(a_time)=:n4 and plant=:n2';
    zhuanli.qzong.sql.text:=s;
    zhuanli.qzong.parambyname('n1').asstring:=combobox1.text;
    zhuanli.qzong.parambyname('n4').value:=strtoint(combobox2.text);
    zhuanli.qzong.parambyname('n2').asstring:=combobox3.text;
    zhuanli.qzong.open;
    end
    else if (edit1.text<>'') and (combobox5.text<>'')
    then
    begin
    zhuanli.qzong.close;
    zhuanli.qzong.sql.clear;
    s:='select * from zong where year(b_time)=:m4 and month(b_time)=:m3';
    zhuanli.qzong.sql.text:=s;
    zhuanli.qzong.parambyname('m4').value:=strtoint(edit1.text);
    zhuanli.qzong.parambyname('m3').value:=strtoint(combobox5.text);
    zhuanli.qzong.open;
    end
    else if (combobox1.text<>'') and (combobox3.text<>'') then
    begin
    s:='select * from zong where p_type=:n1 and plant=:n2' ;
    zhuanli.qzong.sql.text:=s;
    zhuanli.qzong.parambyname('n1').asstring:=combobox1.text;
    zhuanli.qzong.parambyname('n2').asstring:=combobox3.text;
    zhuanli.qzong.open;
    endelse if
    (combobox1.text<>'') and (combobox4.text<>'') then
    begin
    zhuanli.qzong.close;
    zhuanli.qzong.sql.clear;
    s:='select * from zong where p_type=:n1 and flow=:n3' ;
    zhuanli.qzong.sql.text:=s;
    zhuanli.qzong.parambyname('n1').asstring:=combobox1.text;
    zhuanli.qzong.parambyname('n3').asstring:=combobox4.text;
    zhuanli.qzong.open;
    end
    else if
    (combobox1.text<>'') and (combobox2.text<>'') then
    begin
    zhuanli.qzong.close;
    zhuanli.qzong.sql.clear;
    s:='select * from zong where p_type=:n1 and year(a_time)=:n4' ;
    zhuanli.qzong.sql.text:=s;
    zhuanli.qzong.parambyname('n1').asstring:=combobox1.text;
    zhuanli.qzong.parambyname('n4').value:=strtoint(combobox2.text);
    zhuanli.qzong.open;
    endelse if combobox1.text<>'' then
    begin
    zhuanli.qzong.close;
    zhuanli.qzong.sql.clear;
    s:='select * from zong where p_type=:n1' ;
    zhuanli.qzong.sql.text:=s;
    zhuanli.qzong.parambyname('n1').asstring:=combobox1.text;
    zhuanli.qzong.open;
    end;
    end;
    procedure Tmana_Form.Button3Click(Sender: TObject);
    begin
    DBGrid1.readonly:=false;
    zhuanli.zong.edit;
    combobox1.enabled:=false;
    combobox2.enabled:=false;
    combobox3.enabled:=false;
    combobox4.enabled:=false;
    button1.enabled:=false;
    button2.enabled:=false;
    end;procedure Tmana_Form.Button4Click(Sender: TObject);begin
    if messagedlg('您已经修改了数据,请确认!',mtconfirmation,[mbYes,mbno],0)=mrYes
    then
    begin
    dbgrid1.readonly:=true; //使dbgrid处于只读状态
    combobox1.enabled:=true;
    combobox2.enabled:=true;
    combobox3.enabled:=true;
    combobox4.enabled:=true;
    button1.enabled:=true;
    button2.enabled:=true;
    combobox1.text:='';
    combobox2.text:='';
    combobox3.text:='';
    combobox4.text:='';
    end;
    end;
    procedure Tmana_Form.FormCreate(Sender: TObject);
    begin
    DBGrid1.readonly:=true;
    end;procedure Tmana_Form.Button2Click(Sender: TObject);
    begin
    combobox1.text:='';
    combobox2.text:='';
    combobox3.text:='';
    combobox4.text:='';
    end;end.错误信息:project input.exe raised exception class edbengineError with “invalid use of key word.token:year(b_time)=?”,
    line number:1'.