Пример #1
0
        /// <summary>
        /// 执行指定的SqlMapObject
        /// </summary>
        /// <param name="map">指定的SqlMapObject,该对象封装了SqlCommand的必要属性</param>
        /// <returns></returns>
        public static SqlResult ExecuteMapObject(SqlMapObject map)
        {
            if (map == null)
            {
                return(null);
            }

            SqlResult result;

            StatementType stype   = map.GetStatementType();
            CommandType   ctype   = map.GetCommandType();
            string        cmdText = map.Sql;

            SqlParameter[] paras = map.GetParameters();

            // TODO:是否使用事务 from map object
            //bool useTrans = false;
            switch (stype)
            {
            case StatementType.Insert:
                int rowAffected = DBHelper.ExecuteNonQuery(ctype, cmdText, paras);
                result = new SqlResult(rowAffected, stype);
                break;

            case StatementType.Update:
                int rowUpdated = DBHelper.ExecuteNonQuery(ctype, cmdText, paras);
                result = new SqlResult(rowUpdated, stype);
                break;

            case StatementType.Delete:
                int rowDeleted = DBHelper.ExecuteNonQuery(ctype, cmdText, paras);
                result = new SqlResult(rowDeleted, stype);
                break;

            case StatementType.Select:
                DataSet ds = DBHelper.ExecuteDataSet(ctype, cmdText, paras);
                result = new SqlResult(ds, stype);
                break;

            default:
                result = null;
                break;
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// 执行指定的Sql命令
        /// </summary>
        /// <param name="blockName"></param>
        /// <param name="commandName"></param>
        /// <returns></returns>
        public static SqlResult ExecuteMapObject(string blockName, string commandName)
        {
            SqlMapObject map = GetSqlMapObject(blockName, commandName);

            return(ExecuteMapObject(map));
        }