新人自学:
            //创建连接数据库的字符串
            string reportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,
             Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
            reportPath += @"\DataBase\xxpt.mdb";
            string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + reportPath;
            //创建OleDbConnection对象
            OleDbConnection con = new OleDbConnection(ConStr);
            return con;            string reportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,
             Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));这段代码是什么意思啊,是不是文件路径的意思,我主要是连接数据库的操作。

解决方案 »

  1.   

    Application.StartupPath应用程序的可执行文件的路径,就是bin目录里debugsubstirng就是截取字符串
    先看里面的substring从0到最后一个'\'的地方,也就到到****bin然后外面的substring从0到最后一个"\",也就是bin目录的上级目录,也就是更目录了 reportPath += @"\DataBase\xxpt.mdb";在根目录的database文件夹里有xxpt数据库其实就是找到根目录了