| | |
| | | using System.Data; |
| | | using System.Data.SqlClient; |
| | | |
| | | namespace Gs.Toolbox; |
| | | namespace NewPdaSqlServer.util; |
| | | |
| | | /// <summary> |
| | | /// 数据访问类 |
| | |
| | | //数据库连接字符串(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 公用方法 |
| | | |
| | |
| | | else |
| | | str = str + "|" + command.Parameters[a].Value; |
| | | } |
| | | |
| | | return str; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | #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]; |
| | | } |
| | | |
| | | } |