Пример #1
0
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="procename">存储过程名称</param>
        /// <param name="inpars">输入参数</param>
        /// <param name="outpars">输出参数</param>
        public static void ExecuteProce(this Database db, string procename, SQLParaCollection inpars, SQLParaCollection outpars)
        {
            DbCommand command = db.GetStoredProcCommand(procename);

            if (inpars != null)
            {
                foreach (var par in inpars)
                {
                    db.AddInParameter(command, par.Name, par.DbType, par.Value);
                }
            }

            if (outpars != null)
            {
                foreach (var par in outpars)
                {
                    db.AddOutParameter(command, par.Name, par.DbType, 100);
                }
            }

            db.ExecuteNonQuery(command);

            if (outpars != null && outpars.Count > 0)
            {
                foreach (var item in outpars)
                {
                    item.Value = command.Parameters[item.Name].Value;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 查询单值
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="sql">SQL语句</param>
        /// <param name="pars">参数</param>
        /// <returns>结果</returns>
        public static object QuerySingleValue(this Database db, string sql, SQLParaCollection pars)
        {
            DataSet ds = Query(db, sql, pars);

            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0 || ds.Tables[0].Columns.Count == 0)
            {
                return(null);
            }

            return(ds.Tables[0].Rows[0][0]);
        }
Пример #3
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="sql">SQL 语句</param>
        /// <param name="pars">参数</param>
        /// <returns>数据集</returns>
        public static DataSet Query(this Database db, string sql, SQLParaCollection pars)
        {
            DbCommand command = db.GetSqlStringCommand(sql);

            if (pars != null && pars.Count > 0)
            {
                foreach (var par in pars)
                {
                    db.AddInParameter(command, par.Name, par.DbType, par.Value);
                }
            }

            DataSet ds = db.ExecuteDataSet(command);

            return(ds);
        }
Пример #4
0
 /// <summary>
 /// 查询单值
 /// </summary>
 /// <typeparam name="T">单值类型</typeparam>
 /// <param name="db">数据库对象</param>
 /// <param name="sql">SQL语句</param>
 /// <param name="pars">参数</param>
 /// <returns>值</returns>
 public static T QuerySingleValue <T>(this Database db, string sql, SQLParaCollection pars)
 {
     return((T)QuerySingleValue(db, sql, pars));
 }
Пример #5
0
 /// <summary>
 /// 执行存储过程
 /// </summary>
 /// <param name="db">数据库对象</param>
 /// <param name="procename">存储过程名称</param>
 /// <param name="inpars">输入参数</param>
 public static void ExecuteProce(this Database db, string procename, SQLParaCollection inpars)
 {
     ExecuteProce(db, procename, inpars, null);
 }