我用了下面的语句:
   StudentQuery.Close;
   StudentQuery.SQL.Clear;
   StudentQuery.ExecSQL;
   StudentQuery.Close;
   StudentQuery.Open;
运行出错,不知道为什么?

解决方案 »

  1.   

    这是什么意思?
       StudentQuery.Close;
       StudentQuery.SQL.Clear;
       StudentQuery.ExecSQL;
       StudentQuery.Close;
       StudentQuery.Open;
    你把SQL语句都清除了,怎么会不出错?
       StudentQuery.Close;
       StudentQuery.SQL.Clear;
       StudentQuery.SQL.Text := 'Insert into table1(field1)values(1)';
       StudentQuery.ExecSQL;
       
       StudentQuery.Close;
       StudentQuery.SQL.TEXT := 'select * from table1 where field1=1';
       StudentQuery.Open;写上SQL语句之后才不会出错
      

  2.   

    我只是想关掉数据库链接啊,但是单纯用Close的时候一重新打开就出现原来SQL语句的内容,我想全部重新按照条件打开数据库啊?
      

  3.   

    StudentQuery.Close;后重新在DBEdit输入条件,无论怎么输入都为空,不能显示出内容啊?
      

  4.   

    StudentQuery.SQL.Clear; // 清除SQL
    StudentQuery.ExecSQL;  //楼主的目的是什么?
      

  5.   

    没有SQL语句query是不能open的
    至于能不能ExecSQL就不清楚了
      

  6.   

    StudentQuery.Close;
       StudentQuery.SQL.Clear;
       StudentQuery.SQL.Text:='Insert语句';
       StudentQuery.ExecSQL;
       StudentQuery.Close;
       StudentQuery.Open;
    这样执行就不会错了,你没有SQL语句执行StudentQuery.ExecSQL;这句干什么.
    ADOQuery1.Open;//执行查询类的SQL语句
    ADOQuery1.ExecSQL;//执行更新类的SQL语句
      

  7.   

    Open执行之后会返回一个光标,你可以在各个记录之间进行移动。而ExecSQL一般用在insert\update\
    delete等SQL语句的执行,没有返回一个光标。你可以在SQL用参数啦。这是我近来写的数据库的登录语句。
    checkpassword.Close;
        checkpassword.SQL.Clear ;
        checkpassword.SQL.Add('select *  from LoginPersonnel ');
        checkpassword.SQL.Add(' where LoginPersonnel=:LoginPersonnel and PassWords=:PassWords');
        checkpassword.Params[0].AsString:=cb_uesr.Text;
        checkpassword.Params[1].AsString:=passwords.Text;
        checkpassword.open;
      

  8.   

    小错误啦
    写上SQL语句就KO了