示例#1
0
 public void Dispose()
 {
     if (CurrentDbConnection != null)
     {
         if (CurrentDbConnection.State != ConnectionState.Closed)
         {
             if (CurrentTransaction != null)
             {
                 CurrentTransaction.Commit();
             }
             CurrentDbConnection.Close();
         }
         CurrentDbConnection.Dispose();
         CurrentTransaction = null;
     }
 }
示例#2
0
        /// <summary>
        /// 执行查询语句,返回SqlDataReader ( 注意:使用后一定要对SqlDataReader进行Close )
        /// </summary>
        /// <param name="strSql">查询语句</param>
        /// <returns>SqlDataReader</returns>
        public IDataReader ExecuteReader(string strSql)
        {
            SqlCommand command = new SqlCommand(strSql);

            PrepareCommand(command, CurrentDbConnection, CurrentTransaction, CommandType.Text, null);
            SqlDataReader dr = null;

            try
            {
                dr = command.ExecuteReader(CommandBehavior.Default);
                return(dr);
            }
            catch (Exception ex)
            {
                CurrentDbConnection.Close();
                throw ex;
            }
        }
示例#3
0
        /// <summary>
        /// 执行查询语句,返回SqlDataReader ( 注意:使用后一定要对SqlDataReader进行Close )
        /// </summary>
        /// <param name="strSql">SQL语句</param>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>SqlDataReader</returns>
        public IDataReader ExecuteReader(string strSql, params DbParameter[] cmdParms)
        {
            MySqlCommand command = new MySqlCommand(strSql);

            PrepareCommand(command, CurrentDbConnection, CurrentTransaction, CommandType.Text, cmdParms);
            MySqlDataReader dr = null;

            try
            {
                dr = command.ExecuteReader(CommandBehavior.Default);
            }
            catch (Exception ex)
            {
                CurrentDbConnection.Close();
                CurrentDbConnection.Dispose();
                throw ex;
            }
            finally
            {
                command.Parameters.Clear();
            }
            return(dr);
        }