yl
2023-06-30 6fe3d6fc4e93f4cf31dc02d4f0cbc48d56c249b7
VueWebApi/Tools/DapperHelper.cs
@@ -45,6 +45,8 @@
            {
                try
                {
                    //用户操作记录写入数据表
                    //Log4net.LogUtil.SaveMessage("PC", "操作了xxxxx", "api/Login/LoginSave", ConfigurationManager.AppSettings["FileIP"], "9999", 1);
                    list = conn.Query<T>(sql, parm).ToList<T>();
                }
                catch (Exception ex)
@@ -581,5 +583,64 @@
            }
            return result;
        }
        /// <summary>
        /// 执行sql执行语句,返回字符串
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static string sqlstr(String sql)
        {
            string result = "";
            using (IDbConnection conn = sqlConnection())
            {
                try
                {
                    if (result == "")
                    {
                        result = conn.Query<string>(sql).First();
                    }
                }
                catch (Exception ex)
                {
                    //创建日志记录组件实例
                    LogHelper.WriteLog(ex);
                    throw ex;
                }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
            }
            return result;
        }
        public static DataTable lissql(string sql)
        {
            //sql语句
            using (IDbConnection conn = sqlConnection())
            {
                try
                {
                    DataTable table = new DataTable();
                    //var data = conn.ExecuteReader(sql, parm);
                    var res = conn.ExecuteReader(sql);//sql 存储过程
                    table.Load(res);
                    return table;
                }
                catch (Exception ex)
                {
                    //创建日志记录组件实例
                    LogHelper.WriteLog(ex);
                    throw ex;
                }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
            }
        }
    }
}