procedure TForm1.Button1Click(Sender: TObject);
var
SQLstr:string;
begin
SQLstr:='select * from zhendian.db';
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add(SQLstr);
try
  Query1.Prepare;
  Query1.Open;
  Query1.ExecSQL;except
  on EDBEngineError do
  ShowMessage('SQL語句執行出錯!請仔細檢查!');
end;
Query1.Close;
end;这是我的程序,能把数据显示出来,但是显示数据后会出现:“Cannot perform this operation on an open dataset”这是为什么啊?

解决方案 »

  1.   

    Query1.Prepare;
    Query1.Open;
    Query1.ExecSQL;
    不用写这么多吧,一个Open搞定
    错误也许就是因为在Open的后面又ExecSQL
      

  2.   

    不是了,他们两个哪个少了在TDBGrid里都不能显示数据的啊!
      

  3.   


      Query1.Prepare;
      Query1.Open;
      Query1.ExecSQL;///????????这个不要可以吗?
      

  4.   

    //  Query1.ExecSQL; //不要
      

  5.   

    应该是只要 Query1.Open 就行了
      

  6.   

    open返回数据集
    execsql不返回数据集
      

  7.   

    Query1.Close;
    /////////////
    后面这一句干什么的?
    去掉?
      

  8.   

    try
        query1.open
    except
         ...
    end
    就行了。