只用ADO控件,我试过用QUERY尝试查询某个表,结果这样的方法不行

解决方案 »

  1.   

    1.
    try
    begin
       ADOQuery1.Close();
       ADOQuery1.SQL.Text := 'select * from table1';
       ADOQuery1.Open();
    end;
    except
    begin
       ...没有该表
    end;
    2.
    用ADOConnection
    ADOConnection1.GetTableNames(ComboBox1.Items,false)
    把该ADOConnction连的数据库中你的表名都得到了,放到ComboBox1中,下面在判断你的表是不是在里面
      

  2.   


    Adoconnection1.gettablenames(listbox1.items,false);
    if listbox1.items.indexof(tablename)<>-1 then
    //存在
    else
    //不存在
      

  3.   

    用如下的函数,在使用之前请确保AdoQuery1与AdoConnection相连并且AdoConnection已经打开
    function TForm1.IsExist(tb:String):Boolean;
    var
      sql:String;
    begin
      sql:='select * from sysobjects where id=object_id('''+tb+''')';
      AdoQuery1.SQL.Clear;
      AdoQuery1.SQL.Add(sql);
      adoQuery1.Open;
      if AdoQuery1.Recordset.EOF then
        IsExist:=False
      else
        IsExist:=True;
    end;
      

  4.   

    sql:='select * from sysobjects where id=object_id('''+tb+''')';楼上的,这样adoQuery1.Open;如果表不存在会报错吧?
      

  5.   

    sql:='select * from sysobjects where id=object_id('''+tb+''') and xtype = ''U''';
      

  6.   

    对牙,如果表不存在 会报错的
    请问
     AustinLei
     firetoucher
      

  7.   

    ADOConnection1.GetTableNames(ComboBox1.Items,false)
      

  8.   

    TO:myling(阿德) & Pvuanyu(无雨之城)
    没有报错啊,不管表是不是存在都不会报错,我试过了。
      

  9.   

    sysobjects 做何解释?
    xtype = ''U''';
    又是什么意思?
      

  10.   

    sorry,没有说清楚,这是在sql server中的调用。
      

  11.   

    sysobjects是SQLServer和Sybase中的系统表,存储了表名,视图,主键,索引等信息。
    xtype='U' 表
    xtype='V'视图
    如果是其他数据库还是用Adoconnection的遍历进行判断吧