我准备用ado连接excel文件作为数据源
用ado手动连接数据库就可以运行但是我想要用代码动态连接excel作为数据库,我写的代码如下:、procedure Tmainform.FormCreate(Sender: TObject);
var
apppath,str1,str:string;
begin
appPath := ExtractFilePath(Application.ExeName);
str1:=apppath+'小票.xls ';
str:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+str1+';Extended Properties=excel 8.0;Persist Security Info=False';
dm.adocon_test.ConnectionString:=str;
try
dm.adoDS_test.Active:=true;
except
showmessage('连接失败');
end;end;但是每次运行到 dm.adocon_test.ConnectionString:=str; 这一步的时候就会出错
project testprint.exe raised exception class EAccess vicolation with message 'Access violation at address 006Ac1eb in module'textprint.exe',read of address 00000060' process stoppen .use step or run to
求问我出错在哪里?请教学习
用ado手动连接数据库就可以运行但是我想要用代码动态连接excel作为数据库,我写的代码如下:、procedure Tmainform.FormCreate(Sender: TObject);
var
apppath,str1,str:string;
begin
appPath := ExtractFilePath(Application.ExeName);
str1:=apppath+'小票.xls ';
str:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+str1+';Extended Properties=excel 8.0;Persist Security Info=False';
dm.adocon_test.ConnectionString:=str;
try
dm.adoDS_test.Active:=true;
except
showmessage('连接失败');
end;end;但是每次运行到 dm.adocon_test.ConnectionString:=str; 这一步的时候就会出错
project testprint.exe raised exception class EAccess vicolation with message 'Access violation at address 006Ac1eb in module'textprint.exe',read of address 00000060' process stoppen .use step or run to
求问我出错在哪里?请教学习
str := 'Provider=MSDASQL.1;Persist Security Info=False;'
+ 'Driver={Microsoft Excel Driver (*.xls)};DBQ=' + str1;改成这样试一下,你那个是连接Access的,如果还不行,把文件名改为英文的试一下。
在
dm.adocon_test.ConnectionString:=str;
加
dm := tdm.Create(self);
就应该可以了
begin
Application.Initialize;
Application.CreateForm(Tdm, dm);
Application.CreateForm(Tmainform, mainform);
Application.Run;
end.将creatform dm 放在creatform mainform前面也就可以了