Try
  Database1.Connected:=True;
except
  showmessage('数据库错误');
end;     Try
         Begin
            table1.Close;
            table1.TableName:=数据表名;
            table1.Open;
         end
       except
         showmessage('表不存在');
       end;

解决方案 »

  1.   

    这要看是什么数据库,如果是
    sSqlServer可以这样判断:
    LSql := 'select name from sysobject 
    where Name in (''TableName1'',''TableName1'',''TableName1''...) and type = ''U'' '
    如果查询结果为空,则没有
      

  2.   

    其实判断表是否存在可以用一些系统表,或系统视图。
    如:SQL_SERVER的SYSOBJECTS和ORACLE的ALL_TABLES等。看你用什么数据库。
      

  3.   

    LXJ2001(lxj) 
    你能帮我详解一下吗???
    我的数据库是SQL server
      

  4.   

    database=master;user=sa
    Database.Connected:=True; 一个TQUERY
    query.sql.clear;
    query.Sql.Add('select * from sysdatabases where name=''数据库名''');
    query.Open;
    if query.Recordcount>0 then showmessage('database exists');query.sql.clear
    query.sql.add('select * from sysobjects where name in (''表名'',...) and type='U');
    query.open;
      

  5.   

    Session.IsAlias()
    Session.GetAlias()
    Session.GetTablenames()
      

  6.   

    我在用
    query1.sql.add('select * from sysobjects where name in ("operator") and type="U"');
    捡查时错,能帮我看看吗???Porject b.exe raised exception class EDBEngineError with message 'Invalid field name.
    [Microsoft][ODBC SQL Server Driver][SQL server]Invalid column name 'oper'.
    [Microsoft][ODBC SQL Server Driver][SQL server]Invalid column name 'U'.. Process stopped. use step or run to continue.有没有解决方法???
      

  7.   

    if  Session.IsAlias(FAlias) then
    就可以判断一个数据库在不在啦,其它的事就好办了。:)祝你好运
      

  8.   

    是不是用 if Session.isalias('数据表名') then 吗??如果是的话,不行
      

  9.   

    判断数据库系统表的方法不是很好,数据库都连不上,还判断什么?
     Try
        DateBaseType  :=Session.GetAliasDriverName('数据库名称');
      Except
        MessageDlg('请检查是否配置数据库',mtError,[mbOK],0);
        Exit;
      End;  Try
        Database1.Connected:=True;
      Except
         On E: Exception do
         Begin
           MessageDlg('失败!+E.Message,MtError,[mbOK],0);
           Exit;
         End
      End;其他和顶楼的一样,不这些代码扩充以下,就行了
    检查帮助中的TSession。
      

  10.   

    楼上的兄弟们对不起了,给你们添了这么多的麻烦!!!!!我把select * from sysobjects where name in ('operator') and type='U'
    写错了在表名上不能使用双引号”,只能用单的。
    不然在delphi上无法通过