帮忙,烦死了,我在做一个小的系统,dephi+oracle9,因为有比较多的表,所以我想通过adoconnection动态建立数据库连接,然后再把其他的ADOTable控件连到adoconnection, 但我在设置adotable的tablename属性并使active属性为true的时候出错,出错信息如下:            Project Process.exe raised execption class EVariantInvalidOpError with message 'Invalid variant operation '. Process stopped . Use Step or Run to continue;
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, DBTables, StdCtrls, Grids, DBGrids;type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
with ADOConnection1 do
begin
  close;
  LoginPrompt:=false;
  ConnectionString:='Provider = OraOLEDB.Oracle.1;Password=shzf;Persist Security Info=True;User ID=shzf;Data Source=shzf;Extended Properties=""';
  Connected:=true;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    ADOTable1.TableName:='USERINFO';
    ADOTable1.Active:=true;
  except
    showmessage('连接出错');
  end;
end;end.

解决方案 »

  1.   

    adotable1先关掉,然后  再给tablename
      

  2.   

    adotable1.connection:=adoconnection1;
    这句有吗?还是你落了没写?还有,最好这样ADOTable1.Active:=false;
    ADOTable1.TableName:='USERINFO';
    ADOTable1.Active:=true;虽然没关系。但是看上去让人放心:-)
      

  3.   

    但是仔细想了想好像不是这个错
    那样弹出的异常是miss connection之类的信息
    搂主这是你的全部代码吗?那个异常能捕获吗?在设置adoconnection的时候也加个异常捕获,看看到底是哪里的问题
      

  4.   

    myling(阿德) 说的有理,另外在Adoconnection在连接时也捕捉异常,
    看看具体是怎么回事,而且这也是习惯
    with ADOConnection1 do
    begin
      close;
      LoginPrompt:=false;
      ConnectionString:='Provider = OraOLEDB.Oracle.1;Password=shzf;Persist Security Info=True;User ID=shzf;Data Source=shzf;Extended Properties=""';
    try
      Connected:=true;
    except
        //出错信息
    end;
    end;
      

  5.   

    各位兄弟,
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      with ADOConnection1 do
      begin
        close;
        loginprompt:=false;
        ConnectionString:='Provider = OraOLEDB.Oracle.1;Password=shzf;Persist Security Info=True;User ID=shzf;Data Source=shzf;Extended Properties=""';
        Connected:=true;  end;
      ADOTable1.Close;
      adotable1.connection:=adoconnection1;
      ADOTable1.TableName:='USERINFO';
      ADOTable1.Active:=true;
    end;end.ADOConnection连接时一点问题都没有,但一运行到ADOTable1.Active:=true;时就会出错。帮我再看看。
      

  6.   

    oracle没用过ADOTable1.TableName:='USERINFO';猜的,这个表名是否要加上数据库的前缀?如 shzf.USERINFO ?
    猜的,不知对不对
      

  7.   

    还有,说了半天,  try
        ADOTable1.TableName:='USERINFO';
        ADOTable1.Active:=true;
      except
        showmessage('连接出错');
      end;这个异常能捕获吗?
      

  8.   

    兄弟,万分感谢,我试了一下,问题就出在表名应该是shzf.USERINFO上。