小弟日前遇到一新问题!就是不知道怎样判断ADO控件连接数据是否成功!!以前我用的是TRY
  ADOConnect1.Connected := True;
  .......
Except
  Showmessage('数据库连接不成功!')
  .......
End;但现在我必须用ADO控件本身的方法来判断是否连接数据库成功!!请问一下该怎么做呀!

解决方案 »

  1.   

    将ADOConnect1的connected属性设为true,若连接成功,就不会有错误提示,否则,会告诉你连接错误,或者在设置连接字符串时,按测试数据连接按钮也可以判断连接是否成功
      

  2.   

    ADOConnect1.state:=下面stClosed         Connection object is inactive and not connected to a database.
    stOpen         Connection object is inactive, but connected to a database.
    stConnecting Connection object is in the process of connecting to a atabase.
    stExecuting Connection object is currently executing.
    stFetching Connection object is retrieving data from the database.
      

  3.   

    在adoconnection1的afterconnection事件中加入Showmessage('数据库连接不成功!')就可以判断了,当adoconnection的connected属性为true 时,连接成功便不会有错误了。
      

  4.   

    procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
      if stClosed in ADOConnection1.State then
        ShowMessage('Close');
      if stOpen in ADOConnection1.State then
        ShowMessage('Open');
      if stConnecting in ADOConnection1.State then
        ShowMessage('Connecting');
        //.....
    end;end.
      

  5.   

    if adoconnection.connected then
     ...//连上了
    esle
     ...//没连上
      

  6.   

    if adoconn.active then 
    begin
      showmessage('ok');
    end else
    begin
      showmessage('error');
    end;
      

  7.   

    TRY
      adoquery.open;或adoquery.execsql;
      .......
    Except
      Showmessage('数据库连接不成功!')
      .......
    End;
      

  8.   

    你在ado控件的connectionstring中加入連接好后
    if ado.active =true then
    showmessage()
    else
    showmessage();
      

  9.   

    你可以在设置ConnectionString时,在数据链接属性窗体中选择完数据库文件后,点击
    窗体中的测试链接即可。
      

  10.   

    在设计期将ADO连接关闭,然后使用你的程序就可以了