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和我的程序都在桌面的一个文件夹下,我的程序在本地机器上运行正常,在同学的机器上就显示路径不对,我怀疑是这些代码我弄错了,大家帮忙看下!

解决方案 »

  1.   

    dbfilename:=extractfilepath(application.ExeName)+'sfgl.mdb';//数据库名称sfgl.mdb 
    这说明sfg1.mdb是在执行文件的目录下,你是把sfg1.mdb放在桌面上了吧?
      

  2.   

    extractfilepath(application.ExeName)+'\sfgl.mdb'
    这里少了一个'\'吧。
      

  3.   

    Data Source 是你数据库的路径源,及你放sfgl.mdb的路径
      

  4.   

    试试这样可以不,没有密码就不必加那个参数了
    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; 
      

  5.   


    //动态连接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试试这个过程吧!
      

  6.   

    你的程序没问题,仅需要重新编译一下程序~在设计期将Adoconnection的Connected属性变为False即可
      

  7.   

    我用文件打开对话框实现了数据库的连接,你可以看一下。procedure TForm1.Button1Click(Sender: TObject);var  DBPath:String;//DBPath用来存储数据库文件的地址begin
    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;
      

  8.   

    就因为这句话 dbfilename:=extractfilepath(application.ExeName)+'sfgl.mdb';//数据库名称sfgl.mdb 你把数据库的datasource源设置在了应用程序目录下,所以就该把 access文件放回应用文件目录中
    未必要在D盘,只要执行文件在哪个盘,access文件跟到哪个盘就ok了
      

  9.   

    因为桌面文件是在你的主机名文件下,而你的同学的桌面是以你同学主机名存放的
    你的系统文件名叫nilei对吧?你同学的系统文件也叫nilei么?
    如果是的话,那我不说话了,自认明白的太肤浅,静观高人解答
    如果不是的话,你让他在c盘的mydocument文件下建立个叫nilei的文件,然后把程序拷进去
    看看能运行么
      

  10.   

    呵呵 你被那个Format搞晕了
    举个例子 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
      

  11.   

    var
       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’,把它注释掉链接反而正常了,怎么办?各位大侠帮办忙