帮忙,烦死了,我在做一个小的系统,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.
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.
解决方案 »
- 突然想散点分,找不到什么理由!明早结贴!
- Delphi好讨厌哦,竟然乱删我的代码。(这个应该有得设置,请教)
- TWinControl中的滚动条是哪里来的?看了TStringGrid和它的几个祖宗,压根没见ScrollBar
- 讨论:采用那种web开发方式更有效?参与有分!
- Delphi+oracle开发,怎么得到oracle库中任一数据表的所有字段名称?
- 问一个很弱的问题。在线急等。
- 在Delphi中如何调用VC++写的DLL接口?
- 如何声明如下函数
- 请问adoquery和query有什么不同,没分了。谢谢
- 请问delphi xe 如何生成一个标准的 dll, 供 PHP调用?
- 批量复制数据问题,access数据库
- 急求delphi编的局域网聊天系统原代码,谢谢各位大哥了
这句有吗?还是你落了没写?还有,最好这样ADOTable1.Active:=false;
ADOTable1.TableName:='USERINFO';
ADOTable1.Active:=true;虽然没关系。但是看上去让人放心:-)
那样弹出的异常是miss connection之类的信息
搂主这是你的全部代码吗?那个异常能捕获吗?在设置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;
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;时就会出错。帮我再看看。
猜的,不知对不对
ADOTable1.TableName:='USERINFO';
ADOTable1.Active:=true;
except
showmessage('连接出错');
end;这个异常能捕获吗?