VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • 使用Dapper查询记录是否存在

/// <summary>
    /// Dapper数据访问抽象基础类
    /// </summary>
    public class DapperHelper
    {
        public static string connectionString = DESEncrypt.Decrypt(ConfigurationManager.ConnectionStrings["SOACon"].ConnectionString);
        /// <summary>
        /// 连接数据库
        /// </summary>
        /// <returns></returns>
        public static IDbConnection DbConnection()
        {
            var connection = new SqlConnection(connectionString);//连接SQL Server数据库
            connection.Open();
            return connection;
        }

        /// <summary>
        /// 执行是否存在数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sqlStr">查询(例:SELECT COUNT(1)  FROM XXX )</param>
        /// <param name="param">匿名类型</param>
        /// <returns></returns>
        public static bool Exists(string sqlStr, Object param)
        {
            using (IDbConnection conn = DapperHelper.DbConnection())
            {
                int count = conn.Query<int>(sqlStr, param).FirstOrDefault();
                return count > 0 ? true : false;
            }
        }
    }
复制代码

 

调用:

复制代码
#region 判断是否存在库存(不论热前还是热后)

        /// <summary>
        /// 判断是否存在库存(不论热前还是热后)
        /// </summary>
        /// <param name="processCardNumber">流转卡号</param>
        /// <returns></returns>
        public bool ExistInventory(string processCardNumber)
        {
            string sqlStr = " SELECT COUNT(1) FROM udtWip_Inventory WHERE processCardNumber=@processCardNumber ";
            return DapperHelper.Exists(sqlStr, new { processCardNumber = processCardNumber });
        }


        #endregion
复制代码


相关教程