(没有结帖,请回答!!!)一个关于adoconnection的问题(请不要用gettablesname) (10分)

  • 主题发起人 bloodymary
  • 开始时间
B

bloodymary

Unregistered / Unconfirmed
GUEST, unregistred user!
adoconnection 与 d:/data.mdb相连,如何判断data.mdb 是空的(其中不含一个表)?
 
procedure TForm1.Button1Click(Sender: TObject);
var S:TStrings;
begin
S:=TStringList.Create;
ADOConnection1.GetTableNames(S);
if S.Count=0 then //空的
FreeAndNil(S);
end;
 
是这样的,我的Tadoconnection.create(self)的方法(动态指定d:/data.mdb),用这个方法老师出错!!!access violation!!!谁来指点一下,怎么办?(我的data.mdb是空的)
能不能不用gettablesname这个方法,直接判断?
 
源码如下:
procedure tesg;
var
tempado : TAdoconnection;
sl : tstrings;
begin
tempado := TAdoconnection.Create(self);
tempado.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/Data.mdb'+';Persist Security Info=False';
tempado.LoginPrompt := false;
tempado.Connected := true;
tempado.KeepConnection := true; //create tempado;

tempado.GetTableNames(sl,false);//运行在这儿出错!!!
if sl.count = 0 then

showmessage('nil')
//Project Report.exe raised exception class EAccessViolation with message 'Access violation at address 0041EAD7 in module

//'test.exe'. Read of address 00000008'. Process stopped. Use Step or Run to continue.


end;
 
改成这个试试:
var
tempado : TAdoconnection;
sl : tstringList;////更改部分
begin
tempado := TAdoconnection.Create(self);
tempado.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;Data

Source=c:/Data.mdb;Persist Security Info=False';
tempado.LoginPrompt := false;

--------
我测试了可能呀
tempado.Connected := true;

sl:=Tstringlist.Create ; //更改部分
tempado.GetTableNames(sl,false);
if sl.count = 0 then
showmessage('nil')
else
showmessage(inttostr(sl.count));
sl.free;

end;
 
接受答案了.
 

Similar threads

S
回复
0
查看
673
SUNSTONE的Delphi笔记
S
S
回复
0
查看
663
SUNSTONE的Delphi笔记
S
S
回复
0
查看
962
SUNSTONE的Delphi笔记
S
顶部