Const
connstr='Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source=%s;Persist Security Info=False;'+
'Jet OLEDB:Database Password=%s';上面的程序什么意思不明白,比如Data Source=%sprocedure TForm3.FormCreate(Sender: TObject);var
dbfilename:string;
begin
dbfilename:=extractfilepath(application.ExeName)+'sfgl.mdb';//数据库名称sfgl.mdb
adoconnection1.ConnectionString:=format(connstr,[dbfilename,'']);//数据库无密码
adoconnection1.Open;
end;数据库文件sfgl.mdb和我的程序都在桌面的一个文件夹下,我的程序在本地机器上运行正常,在同学的机器上就显示路径不对,我怀疑是这些代码我弄错了,大家帮忙看下!
connstr='Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source=%s;Persist Security Info=False;'+
'Jet OLEDB:Database Password=%s';上面的程序什么意思不明白,比如Data Source=%sprocedure TForm3.FormCreate(Sender: TObject);var
dbfilename:string;
begin
dbfilename:=extractfilepath(application.ExeName)+'sfgl.mdb';//数据库名称sfgl.mdb
adoconnection1.ConnectionString:=format(connstr,[dbfilename,'']);//数据库无密码
adoconnection1.Open;
end;数据库文件sfgl.mdb和我的程序都在桌面的一个文件夹下,我的程序在本地机器上运行正常,在同学的机器上就显示路径不对,我怀疑是这些代码我弄错了,大家帮忙看下!
解决方案 »
- 有没有办法可以将quickrep报表另存为EXCEL啊?
- CxGrid中的自动滚屏问题,急!!
- 怎样进行事务嵌套
- 一个简单的对比,怎样用SQL实现?详请请进。
- 关于除法的问题。。简单。解决了,马上给分
- Delphi + Oracle8i , 请问你是用了什么数据控件和Oracle 连接的?
- 急,我用delphi做了一个聊天工具的,当客户端出现一起登陆时,服务器响应连接超时,然后就出现死机,关不掉
- 谁能帮我
- 一个问题,建立的 FB: TBevel没显示,好象根本没建立一样。
- 急疯了,急疯了!我的输入框DBEdit1为什么老报错
- delphi hdc啥意思》?
- 已经知道进程名和进程id,如何取线程id
这说明sfg1.mdb是在执行文件的目录下,你是把sfg1.mdb放在桌面上了吧?
这里少了一个'\'吧。
procedure TForm3.FormCreate(Sender: TObject);
var
ConStr :string;
begin
ConStr := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractfilePath(Application.ExeName)+'\file.mdb;Persist Security Info=True';
try
adoconnection1.Connected := false;
adoconnection1.ConnectionString:=ConStr;/
adoconnection1.Connected := true;
showmessage('联接成功');
except
showmessage('联接失败');
end;
end;
//动态连接Access数据库
procedure TF_main.ConnectDB;
var
ConnStr,DBPath,Msg:String;
begin
DBPath:= ExtractFilePath(Application.ExeName)+'\sfgl.mdb';
if not FileExists(DBPath) then
begin
Msg:= '数据库文件路径设置不对!';
Application.MessageBox(Pchar(Msg),'数据库连接错误!',MB_OK+MB_ICONERROR);
Application.Terminate;
end;
ConnStr:= 'Provider=Microsoft.Jet.OLEDB.4.0;'
+'Data Source='+DBPath
+';Persist Security Info=False';
ADOConnection1.Close;
ADOConnection1.ConnectionString:=ConnStr;
DM_1.ADOconnection1.LoginPrompt:=False;
try
ADOConnection1.Connected:= True
except
Application.MessageBox('数据库连接错误,请重试!','错误',MB_OK+MB_ICONERROR);
Application.Terminate;
end;
end;
在联接数据库时,直接用这个过程:ConnectDB试试这个过程吧!
OpenDialog1.Execute; If OpenDialog1.FileName='' then Exit; //没有打开文件,结束事件 //以下设置ADOConnection连接
DBPath := 'Provider=Microsoft.Jet.OLEDB.4.0;Password="";';
DBPath := DBPath + 'Data Source=' + OpenDialog1.FileName+';';
DBPath := DBPath + 'Persist Security Info=True';
ADOConnection1.ConnectionString := DBPath;end;
未必要在D盘,只要执行文件在哪个盘,access文件跟到哪个盘就ok了
你的系统文件名叫nilei对吧?你同学的系统文件也叫nilei么?
如果是的话,那我不说话了,自认明白的太肤浅,静观高人解答
如果不是的话,你让他在c盘的mydocument文件下建立个叫nilei的文件,然后把程序拷进去
看看能运行么
举个例子 format('我的CSDN可用分是:%s,我的专家分是:%s,我的裤叉有:%s条',['1000','4000','5'])
输出的就是 '我的CSDN可用分是:1000,我的专家分是:4000,我的裤叉有:5条'
其中%s表示字符串 %d整型 %f浮点
至于你的问题在
ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source'
+extractfilepath(application.ExeName)
+'db1.mdb;Persist Security Info=False';
这样就可以
如果还不行
试试不要有中文路径 再不行升级MDAC
constr:string;
filepath:string;
begin
//Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\新建文件夹\delphi程序\20110503\Database\DB.mdb;Persist Security Info=False
filepath:=ExtractFilepath(Paramstr(0));
filepath:=filepath+'\Database\DB.mdb';
constr:='Microsoft.Jet.OLEDB.4.0;'
+'Data Source='+filepath+';'+'Persist Security Info=False';
self.ADOConnection1.Close;
self.ADOConnection1.ConnectionString:=constr;
self.ADOConnection1.Open;
end;
运行时总是出现找不到可安装的‘isam’,把它注释掉链接反而正常了,怎么办?各位大侠帮办忙