Exemple #1
0
        /// <summary>
        /// 获取数据库命令接口
        /// </summary>
        /// <param name="cmdText">查询语句</param>
        /// <returns>返回数据库命令接口</returns>
        protected IDbCommand GetCommand(string cmdText, IDictionary <string, object> pars, CommandType cmdType = CommandType.Text)
        {
            //创建数据库命令
            IDbCommand cmd = dbFactory.CreateCommand();

            cmd.CommandType = cmdType;
            //设置数据源运行的文本命令
            cmd.CommandText = cmdText;
            //设置连接
            cmd.Connection = connection;

            if (pars != null)
            {
                cmd.Parameters.Clear();
                foreach (var p in pars)
                {
                    var v = p.Value;
                    if (v == null)
                    {
                        v = DBNull.Value;
                    }
                    cmd.Parameters.Add(CreateParam(cmd, p.Key, v));
                }
            }

            if (ExecuteSqlCallback != null)
            {
                ExecuteSqlCallback.BeginInvoke(cmdText, null, pars);
            }

            return(cmd);
        }
Exemple #2
0
        /// <summary>
        /// 获取数据库命令接口
        /// </summary>
        /// <param name="cmdText"></param>
        /// <param name="cmdType"></param>
        /// <returns></returns>
        protected IDbCommand GetCommand(string cmdText, CommandType cmdType = CommandType.Text)
        {
            //创建数据库命令
            IDbCommand cmd = dbFactory.CreateCommand();

            cmd.CommandType = cmdType;
            //设置数据源运行的文本命令
            cmd.CommandText = cmdText;
            //设置连接
            cmd.Connection = connection;

            if (ExecuteSqlCallback != null)
            {
                ExecuteSqlCallback.BeginInvoke(cmdText, null, cmdType);
            }

            return(cmd);
        }