C#连接数据库时的相对路径

2025-04-08 19:10:19
推荐回答(1个)
回答1:

1、配置文件








2、实例化时传参,Application.StartupPath返回当前程序运行路径。
DBHelper db = new DBHelper(Application.StartupPath);
3、构造方法
public DBHelper(string dbPath)
{
this.connString = this.connString.Replace("|path|", dbPath);
}