Beispiel #1
0
        public DataSet ExecuteDataSet(string spName, ConnectionState connectionstate, params object[] parameterValues)
        {
            DbDataAdapter adapter = objFactory.CreateDataAdapter();

            DbParameter[] parameters = ParameterCache.GetSpParameterSet(objConnection, spName);
            AssignParameterValues(parameters, parameterValues);
            objCommand.Parameters.AddRange(parameters);

            adapter.SelectCommand = objCommand;
            DataSet ds = new DataSet();

            try
            {
                adapter.Fill(ds);
            }
            catch (Exception ex)
            {
                HandleExceptions(ex);
            }
            finally
            {
                objCommand.Parameters.Clear();
                if (connectionstate == ConnectionState.CloseOnExit)
                {
                    if (objConnection.State == System.Data.ConnectionState.Open)
                    {
                        objConnection.Close();
                    }
                }
            }
            return(ds);
        }
Beispiel #2
0
        public object ExecuteScalar(string spName, ConnectionState connectionstate, params object[] parameterValues)
        {
            objCommand.CommandText = spName;
            objCommand.CommandType = CommandType.StoredProcedure;

            DbParameter[] parameters = ParameterCache.GetSpParameterSet(objConnection, spName);
            AssignParameterValues(parameters, parameterValues);
            objCommand.Parameters.AddRange(parameters);

            object o = null;

            try
            {
                if (objConnection.State == System.Data.ConnectionState.Closed)
                {
                    objConnection.Open();
                }
                o = objCommand.ExecuteScalar();
            }
            catch (Exception ex)
            {
                HandleExceptions(ex);
            }
            finally
            {
                objCommand.Parameters.Clear();
                if (connectionstate == ConnectionState.CloseOnExit)
                {
                    objConnection.Close();
                }
            }

            return(o);
        }
Beispiel #3
0
        public DbDataReader ExecuteReader(string spName, ConnectionState connectionstate, params object[] parameterValues)
        {
            objCommand.CommandText = spName;
            objCommand.CommandType = CommandType.StoredProcedure;

            DbParameter[] parameters = ParameterCache.GetSpParameterSet(objConnection, spName);
            AssignParameterValues(parameters, parameterValues);
            objCommand.Parameters.AddRange(parameters);

            DbDataReader reader = null;

            try
            {
                if (objConnection.State == System.Data.ConnectionState.Closed)
                {
                    objConnection.Open();
                }
                if (connectionstate == ConnectionState.CloseOnExit)
                {
                    reader = objCommand.ExecuteReader(CommandBehavior.CloseConnection);
                }
                else
                {
                    reader = objCommand.ExecuteReader();
                }
            }
            catch (Exception ex)
            {
                HandleExceptions(ex);
            }
            finally
            {
                objCommand.Parameters.Clear();
            }

            return(reader);
        }