平台:vs2005  语言:c#
是windows应该程序(不是网页),要相对路径不是绝对路径,还有我的数据库设了密码,请各位高手写一句

解决方案 »

  1.   

    using System.IO;
    using System.Data.OleDb;OleDbConnection vOleDbConnection = new OleDbConnection();
    vOleDbConnection.ConnectionString = string.Format(
        @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
        @"{0}\temp.mdb;User ID=admin;Password=;" +
        @"Jet OLEDB:Database Password=111111", 
        Path.GetDirectoryName(Application.ExecutablePath));
    vOleDbConnection.Open();
      

  2.   

    Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Directory.GetCurrentDirectory() + access文件名称
      

  3.   

    try..
                string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\Northwind.mdb";
                string constr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + path + ";User ID=Admin;Password=123;";
      

  4.   

    don't forgetusing System.IO;
    using System.Reflection;
    using System.Data.OleDb;
      

  5.   

    路径用: Path.Combine(Directory.GetCurrentDirectory(),"相对路径")
      

  6.   

    OleDbConnection OleCon;//Connection对象
                    string ConString;//连接字符串
                    string AppPath;                AppPath = Application.ExecutablePath();//取得当前的可执行文件的路径
                    
                    if (!AppPath.EndsWith(@"\")) AppPath += @"\";//判断是否在根目录            ConString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" + AppPath+[your Database Name] + ";Database Password=[your Database Password];";
                OleCon = new OleDbConnection(this.ConString);//实例化Connection对象
      

  7.   

    OleDbConnection OleCon;//Connection对象
                    string ConString;//连接字符串
                    string AppPath;                AppPath = Application.ExecutablePath();//取得当前的可执行文件的路径
                    
                    if (!AppPath.EndsWith(@"\")) AppPath += @"\";//判断是否在根目录            ConString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" + AppPath+[your Database Name] + ";Database Password=[your Database Password];";
                OleCon = new OleDbConnection(this.ConString);//实例化Connection对象
      

  8.   

    无法启动应用程序。工作组信息文件丢失,或是已被其它用户以独占方式打开各位高手,你们的字符串我用上了怎么都有以上的错误提示啊?还有  liujia_0421(SnowLover) 兄台:
    你能不能解析一下你的
    string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\Northwind.mdb";这段的意思?
    我真的想彻底理解这个问题
      

  9.   

    楼主你的两个三角是怎么来的?显示出来看看是不是存在这个文件MessageBox.Show(path );Assembly.GetEntryAssembly().Location得到程序文件名
    如:c:\temp\temp.exe
    Path.GetDirectoryName()返回文件路径
    如:Path.GetDirectoryName("c:\temp\temp.exe") = "c:\temp"这些不用问的,直接调试或者查MSND都可以知道
    有问题就把你的代码贴出来看看
      

  10.   

    TO:还有  liujia_0421(SnowLover) 兄台:
    你能不能解析一下你的
    string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\Northwind.mdb";这段的意思?伴水清清已经讲得很清楚了...
      

  11.   

    请注意将你的mdb文件放在与你的可执行文件同一个目录下..比如:E:\C#学习之路\Projects\TestConsole\TestConsole\bin\Debug