我的代码如下:
procedure TFrmShow.selectClick(Sender: TObject);
begin
  ibquery1.close;
  if not (ibquery1.prepared) then ibquery1.prepare;
  ibquery1.First;//!!!!error:cannot perform the operation on a closed dataset
  if not ibquery1.eof then
  begin
    ibquery1.ParamByName('inusercode').AsString:=usercode.text;
    ibquery1.ParamByName('inmetercode').AsString:=metercode.text;
    ibquery1.ParamByName('inreaddate').AsString:=MEdate.text;
    ibquery1.ParamByName('inreadtype').Asinteger:=strtoint(leftstr(metertype.text,1));
    ibquery1.Open;
  end;
  ibquery1.UnPrepare;
  ShowMessage(inttostr(ibquery1.RecordCount));
end;
属性设置如下
 datesource1.dataset:ibquery1
 dbgrid.datasource:datesource1
我整了老半天都没搞定。说什么是关闭的数据集,我该怎么办?求助个大虾!!

解决方案 »

  1.   

    ibquery1.First;//!!!!error:cannot perform the operation on a closed dataset
      if not ibquery1.eof then
    --------------------------------这些都是没用的
      

  2.   

    在执行这里之前:ibquery1.First;//!!!!error:cannot perform the operation on a closed dataset
    先打开ibquery1
      

  3.   

    这段代码自相矛盾。去掉以下项:
    ibquery1.First;//!!!!error:cannot perform the operation on a closed dataset
      if not ibquery1.eof then
      

  4.   

    在 ibquery1.First; 之前加上 ibquery1.open;
    前提是你的ibquery1中已经有了合法的sql语句
      

  5.   

    那些提示有时候不室那么回事,看看你的sql 语句 真的是明智之举
      

  6.   

    没有打开数据库呢怎么FIRST呢
    在OPEN之后再FIRST
      

  7.   

    我想应该是这样
    procedure TFrmShow.selectClick(Sender: TObject);
    begin
      ibquery1.close;
      If ibquery1.Active=False then ibquery1.open;
      If not (ibquery1.state in [dsEdit]) then ibquery1.Edit;
      ibquery1.sql.Clear;
      ibquery1.sql.add('这里你的sql语句');
      ibquery1.open;
      if not ibquery1.isEmpty then  
      begin
        ibquery1.ParamByName('inusercode').AsString:=usercode.text;
        ibquery1.ParamByName('inmetercode').AsString:=metercode.text;
        ibquery1.ParamByName('inreaddate').AsString:=MEdate.text;
        ibquery1.ParamByName('inreadtype').Asinteger:=strtoint(leftstr(metertype.text,1));
      end;
      ibquery1.post;
      ShowMessage(inttostr(ibquery1.RecordCount));
    end;
      

  8.   

    procedure TFrmShow.selectClick(Sender: TObject);
    begin
      ibquery1.close;
      begin
        ibquery1.ParamByName('inusercode').AsString:=usercode.text;
        ibquery1.ParamByName('inmetercode').AsString:=metercode.text;
        ibquery1.ParamByName('inreaddate').AsString:=MEdate.text;
        ibquery1.ParamByName('inreadtype').Asinteger:=strtoint(leftstr(metertype.text,1));
        ibquery1.Open;
      end;
    end;
    先把基本的实现语名运行一下,然后再加上判断语句调试
      

  9.   

    在 ibquery1.First; 之前加上 ibquery1.open;
    前提是你的ibquery1中已经有了合法的sql语句
      

  10.   

    你再把Query的RequestLive属性设置为True试试
      

  11.   

    ShowMessage(inttostr(ibquery1.RecordCount));纪录数为零!
      

  12.   

    你的Query都没有Open,怎么能用First呢?