• MySql_DBHelper


    public class DBHelper
        {
            //System.Data.SqlClient
            //Dapper
            //Newtonsoft.Json
    
            /// <summary>
            /// 查询List集合
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="sql"></param>
            /// <returns></returns>
            public static List<T> GetList<T>(string sql)
            {
                try
                {
                    using (MySqlConnection conn=new MySqlConnection(AppsettingsHelper.AppConfigOwn.SqlConnString))
                    {
                        return conn.Query<T>(sql).ToList();
                    }
                }
                catch(Exception)
                {
                    throw;
                }
            }
    
            /// <summary>
            /// 增删改
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public static int Exec(string sql)
            {          
                try
                {
                    using (MySqlConnection conn=new MySqlConnection(AppsettingsHelper.AppConfigOwn.SqlConnString))
                    {
                        return conn.Execute(sql);
                    }
                }
                catch(Exception)
                {
                    throw;
                }
            }
    
            /// <summary>
            /// 二级联动
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public int GetSaler(string sql)
            {
                try
                {
                    using (MySqlConnection conn=new MySqlConnection(AppsettingsHelper.AppConfigOwn.SqlConnString))
                    {
                        return conn.ExecuteScalar<int>(sql);
                    }
                }
                catch(Exception)
                {
                    throw;
                }
            }
    
            /// <summary>
            /// 使用事务执行sql
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public static int ExecTransaction(string sql)
            {
                try
                {
                    using (MySqlConnection conn = new MySqlConnection(AppsettingsHelper.AppConfigOwn.SqlConnString))
                    {
                        IDbTransaction transaction = conn.BeginTransaction();
                        int a= conn.Query<int>(sql,transaction).AsList()[0];
                        transaction.Commit();
                        return a;
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
    
            /// <summary>
            /// 返回首行首列
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public static int ExexCount(string sql)
            {
                try
                {
                    using (MySqlConnection conn = new MySqlConnection(AppsettingsHelper.AppConfigOwn.SqlConnString))
                    {
                        return conn.ExecuteScalar<int>(sql);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
  • 相关阅读:
    const void *a 与 void *const a 的差别
    unity中的MonoBehaviour.OnMouseDown()
    ZooKeeper场景实践:(2)集中式配置管理
    也谈測试核心竞争力
    关于静态与动态编译arm平台程序的比較
    使用Nexus搭建企业maven仓库(二)
    cocos2dx手写js绑定C++
    HDU2037 今年暑假不AC 【贪心】
    Android的NDK开发(2)————利用Android NDK编写一个简单的HelloWorld
    Android的NDK开发(1)————Android JNI简介与调用流程
  • 原文地址:https://www.cnblogs.com/lyboke/p/14837783.html
Copyright © 2020-2023  润新知