//数据库名字为calendar.mdb
var
  con: TADOConnection;
    
  con.Connected := False;
  con.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + ExtractFilePath(ParamStr(0)) + 'calendar.mdb;Persist Security Info=True';
  con.Connected := True;

解决方案 »

  1.   

    dim yourpath as string
    if right(app.path,1)="\" then
       yourpath=app.path & "youraccess.mdb"
    else
       yourpath=app.path & "\youraccess.mdb"
    end if
      

  2.   

    dim yourpath as string
    if right(app.path,1)="\" then
       yourpath=app.path & "youraccess.mdb"
    else
       yourpath=app.path & "\youraccess.mdb"
    end ifconn.connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & yourpath &";Persist Security Info=True"
      

  3.   

    你的答复是用ADO对象的相对路径设置编码吗?
    用ADODC连接ACCESS,能设相对路径吗?
    另外,请问,VB程序打包的时候,有必要把数据库也打进去吗?
      

  4.   

    是不是每个ADO控件在连接SQL查询语句之前都要添加这些代码呢?
    如果将来ACCESS导入SQL数据库,对SQL数据库的相对路径设置,只要改变Adodc.Connectionstring的赋值吗?
    数据库文件的存放位置有必要和VB程序放在一个文件夹里吗?
    如果是SQL数据库,打包的时候也要打进去吗?