Example #1
0
        /// <summary>
        /// 这个方法返回sql语句执行后的第一行第一列的值
        /// </summary>
        /// <param name="cmdType">命令类型</param>
        /// <param name="cmdText">查询语句</param>
        /// <param name="objParams">查询语句参数</param>
        /// <returns>返回结果</returns>
        public static object ExecuteScalar(CommandType cmdType, string cmdText, params ObjectParameter[] objParams)
        {
            object objResult = null;

            switch (DbType.ToLower())
            {
            case "oracle":
                objResult = OracleDbHelper.ExecuteScalar(DbConnectionString, cmdType, FormatCommandText(cmdText), ObjectParamterToOracleParameter(objParams));
                break;

            case "sql":
                objResult = SqlDbHelper.ExecuteScalar(DbConnectionString, cmdType, FormatCommandText(cmdText), ObjectParamterToSqlParameter(objParams));
                break;
            }
            return(objResult);
        }
Example #2
0
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <returns>OracleDataReader</returns>
        public static DbDataReader RunProcedure(string storedProcName, IDataParameter[] parameters)
        {
            DbDataReader drResult = null;

            switch (DbType.ToLower())
            {
            case "oracle":
                drResult = OracleDbHelper.RunProcedure(DbConnectionString, storedProcName, parameters);
                break;

            case "sql":
                drResult = SqlDbHelper.RunProcedure(DbConnectionString, storedProcName, parameters);
                break;
            }
            return(drResult);
        }
Example #3
0
        /// <summary>
        /// 执行查询语句,返回OracleDataReader
        /// </summary>
        /// <param name="cmdType">命令类型</param>
        /// <param name="cmdText">查询语句</param>
        /// <returns>返回结果</returns>
        public static DbDataReader ExecuteReader(CommandType cmdType, string cmdText)
        {
            DbDataReader drResult = null;

            switch (DbType.ToLower())
            {
            case "oracle":
                drResult = OracleDbHelper.ExecuteReader(DbConnectionString, cmdType, cmdText);
                break;

            case "sql":
                drResult = SqlDbHelper.ExecuteReader(DbConnectionString, cmdType, cmdText);
                break;
            }
            return(drResult);
        }
Example #4
0
        /// <summary>
        /// 重载ExecuteNonQuery方法,实现对事务处理的可选择性.
        /// </summary>
        /// <param name="cmdType">命令类型</param>
        /// <param name="cmdText">查询语句</param>
        /// <param name="objParams">查询语句参数</param>
        /// <param name="isTrans">是否使用事务处理</param>
        /// <returns>返回结果</returns>
        public static int ExecuteNonQuery(CommandType cmdType, string cmdText, bool isTrans, params ObjectParameter[] objParams)
        {
            int iResult = -1;

            switch (DbType.ToLower())
            {
            case "oracle":
                iResult = OracleDbHelper.ExecuteNonQuery(DbConnectionString, cmdType, FormatCommandText(cmdText), isTrans, ObjectParamterToOracleParameter(objParams));
                break;

            case "sql":
                iResult = SqlDbHelper.ExecuteNonQuery(DbConnectionString, cmdType, FormatCommandText(cmdText), isTrans, ObjectParamterToSqlParameter(objParams));
                break;
            }
            return(iResult);
        }
Example #5
0
        /// <summary>
        /// 执行查询语句,返回一个DataSet对象
        /// </summary>
        /// <param name="cmdType">命令类型</param>
        /// <param name="cmdText">查询语句</param>
        /// <param name="objParams">查询语句参数</param>
        /// <returns>返回结果</returns>
        public static DataSet Query(CommandType cmdType, string cmdText, params ObjectParameter[] objParams)
        {
            DataSet dsResult = null;

            switch (DbType.ToLower())
            {
            case "oracle":
                dsResult = OracleDbHelper.Query(DbConnectionString, cmdType, FormatCommandText(cmdText), ObjectParamterToOracleParameter(objParams));
                break;

            case "sql":
                dsResult = SqlDbHelper.Query(DbConnectionString, cmdType, FormatCommandText(cmdText), ObjectParamterToSqlParameter(objParams));
                break;
            }
            return(dsResult);
        }
Example #6
0
        /// <summary>
        /// 执行查询语句,返回DataSet对象
        /// </summary>
        /// <param name="cmdText">查询语句</param>
        /// <returns>返回结果</returns>
        public static DataSet Query(string cmdText)
        {
            DataSet dsResult = null;

            switch (DbType.ToLower())
            {
            case "oracle":
                dsResult = OracleDbHelper.Query(DbConnectionString, cmdText);
                break;

            case "sql":
                dsResult = SqlDbHelper.Query(DbConnectionString, cmdText);
                break;
            }
            return(dsResult);
        }
Example #7
0
        /// <summary>
        /// 检查记录是否存在
        /// </summary>
        /// <param name="cmdText">查询语句</param>
        /// <param name="objParams">查询语句参数</param>
        /// <returns>返回结果</returns>
        public static bool Exists(string cmdText, params ObjectParameter[] objParams)
        {
            bool bResult = false;

            switch (DbType.ToLower())
            {
            case "oracle":
                bResult = OracleDbHelper.Exists(DbConnectionString, FormatCommandText(cmdText), ObjectParamterToOracleParameter(objParams));
                break;

            case "sql":
                bResult = SqlDbHelper.Exists(DbConnectionString, FormatCommandText(cmdText), ObjectParamterToSqlParameter(objParams));
                break;
            }
            return(bResult);
        }
        /// <summary>
        /// 检查记录是否存在
        /// </summary>
        /// <param name="connString">数据库连接字符串</param>
        /// <param name="cmdText">查询语句</param>
        /// <param name="cmdParams">查询语句参数</param>
        /// <returns>返回结果</returns>
        public static bool Exists(string connString, string cmdText, params OracleParameter[] cmdParams)
        {
            object obj = OracleDbHelper.GetSingle(connString, cmdText, cmdParams);
            int    cmdresult;

            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }