示例#1
0
        /// <summary>
        /// 执行查询语句,返回DataSet
        /// </summary>
        /// <param name="SQLString">查询语句</param>
        /// <returns>DataSet</returns>
        public DataSet GetDataSet(string SQLString, params DbParameter[] cmdParms)
        {
            DataSet         ds           = new DataSet();
            DbConnection    conn         = DbInstance.Database.Connection;
            ConnectionState initialState = conn.State;

            try
            {
                if (initialState != ConnectionState.Open)
                {
                    conn.Open();
                }
                DbCommand cmd = conn.CreateCommand();
                PrepareCommand(cmd, null, SQLString, cmdParms);
                using (DbDataAdapter da = new DalDBFactory().GetDbDataAdapter(cmd, this.GetDBType()))
                {
                    da.Fill(ds, "ds");
                    cmd.Parameters.Clear();
                }
            }
            catch (Exception ex)
            {
                logger.Error("GetDataSet:" + ex.Message);
                throw ex;
            }
            finally
            {
                if (initialState != ConnectionState.Open)
                {
                    conn.Close();
                }
            }

            return(ds);
        }
示例#2
0
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="storedProcName"></param>
        /// <param name="parameters"></param>
        /// <param name="tableName"></param>
        /// <param name="Times"></param>
        /// <returns></returns>
        public DataSet RunProcedure(string storedProcName, DbParameter[] parameters, int Times)
        {
            DataSet         ds           = new DataSet();
            DbConnection    conn         = DbInstance.Database.Connection;
            ConnectionState initialState = conn.State;

            try
            {
                if (initialState != ConnectionState.Open)
                {
                    conn.Open();
                }
                using (DbDataAdapter sqlDA = new DalDBFactory().GetDbDataAdapter(this.GetDBType()))
                {
                    sqlDA.SelectCommand = BuildQueryCommand(conn.CreateCommand(), storedProcName, parameters);
                    sqlDA.SelectCommand.CommandTimeout = Times;
                    sqlDA.Fill(ds);
                }
            }
            catch (Exception ex)
            {
                logger.Error("RunProcedure:" + ex.Message);
                throw ex;
            }
            finally
            {
                if (initialState != ConnectionState.Open)
                {
                    conn.Close();
                }
            }

            return(ds);
        }
示例#3
0
        /// <summary>
        /// 执行查询语句,返回DataSet
        /// </summary>
        /// <param name="SQLString">查询语句</param>
        /// <param name="Times">超时</param>
        /// <returns>DataSet</returns>
        public DataSet GetDataSet(string SQLString, int Times)
        {
            DataSet         ds           = new DataSet();
            DbConnection    conn         = DbInstance.Database.Connection;
            ConnectionState initialState = conn.State;

            try
            {
                if (initialState != ConnectionState.Open)
                {
                    conn.Open();
                }
                using (DbDataAdapter command = new DalDBFactory().GetDbDataAdapter(SQLString, conn, this.GetDBType()))
                {
                    command.SelectCommand.CommandTimeout = Times;
                    command.Fill(ds, "ds");
                }
            }
            catch (Exception ex)
            {
                logger.Error("GetDataSet:" + ex.Message);
                throw ex;
            }
            finally
            {
                if (initialState != ConnectionState.Open)
                {
                    conn.Close();
                }
            }

            return(ds);
        }