111
啊鑫
昨天 971e03ccbe5124d4761f56e71025453d1d4742bc
util/DbHelperSQL.cs
@@ -2,7 +2,7 @@
using System.Data;
using System.Data.SqlClient;
namespace Gs.Toolbox;
namespace NewPdaSqlServer.util;
/// <summary>
///     数据访问类
@@ -12,6 +12,24 @@
    //数据库连接字符串(web.config来配置)   
    public static readonly string strConn =
        getValueByKey("DataBaseConn");
    public static string getValueByKey(string key)
    {
        // 创建配置构建器
        var builder = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true);
        // 构建配置
        var configuration = builder.Build();
        // 修复配置路径:如果是DataBaseConn,需要从AppSettings节点读取
        if (key == "DataBaseConn")
        {
            return configuration["AppSettings:DataBaseConn"];
        }
        return configuration[key];
    }
    #region 公用方法
@@ -571,6 +589,7 @@
            else
                str = str + "|" + command.Parameters[a].Value;
        }
        return str;
    }
@@ -672,17 +691,4 @@
    }
    #endregion
    public static string getValueByKey(string key)
    {
        // 创建配置构建器
        var builder = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", true, true);
        // 构建配置
        var configuration = builder.Build();
        return configuration[key];
    }
}