在ado+access中 ,如何判断一个表是否存在?谢谢

解决方案 »

  1.   

    var
      SL:TStrings;
      index:integer;
    begin
      SL:=TStringList.Create ;
      Try
        //返回数据库表名
          form1.ADOConnection1.GetTableNames(SL,False);
           for index:=0 to (SL.Count -1) do
           begin
                form1.Adotable1.TableName :=SL[index];
                form1.ListBox1 .Items.Add(SL[index]);
           end;
        finally
          SL.Free;
        end;
        listbox1.Show;
    得到表名后循环判断是否存在
    listbox1中存了表名
      

  2.   

    谢谢,高手能不能帮我写一个比如像
    ExistTable (tablename)  :boolean 的函数?
    万分感激。
      

  3.   

    function ExistTable(cnn:TADOConnection;TableName:string): boolean;
    var
      tables:Tstrings;
    begin
      Result:=False ;
      tables:= TStringList.Create ;
      try
        cnn.GetTableNames(tables);
        if  tables.IndexOf(TableName)>-1 then
          Result:=True ;
      finally
        tables.Free ;
      end;
    end;