예제 #1
0
        public int ExecuteScalar(string strSQL, params SqlParameter[] Parameters)
        {
            int      temp   = 0;
            DBAccess myBase = new DBAccess();

            try
            {
                SqlConnection myConn    = myBase.OpenConnection(connectionString);
                SqlCommand    myCommand = new SqlCommand(strSQL, myConn);
                myCommand.Parameters.Clear();
                foreach (SqlParameter par in Parameters)
                {
                    myCommand.Parameters.Add(par);
                }

                temp = Convert.ToInt32(myCommand.ExecuteScalar().ToString());
                myCommand.Dispose();
                myBase.CloseConnection(myConn);
                return(temp);
            }
            catch (Exception myException)
            {
                throw (new Exception(myException.Message + " => " + strSQL));
            }
        }
예제 #2
0
        public SqlDataReader getReader(SqlCommand cmd)
        {
            DBAccess myBase = new DBAccess();

            try
            {
                SqlConnection myConn = myBase.OpenConnection(connectionString);
                cmd.Connection = myConn;
                SqlDataReader reader = cmd.ExecuteReader();
                //myBase.CloseConnection(myConn);
                return(reader);
            }
            catch (Exception myException)
            {
                throw (new Exception(myException.Message + " => " + cmd.CommandText));
            }
        }
예제 #3
0
        public void ExecuteSQL(SqlCommand mCommand)
        {
            DBAccess myBase = new DBAccess();

            try
            {
                SqlConnection myConn = myBase.OpenConnection(connectionString);
                mCommand.Connection = myConn;
                mCommand.ExecuteNonQuery();

                mCommand.Dispose();
                myBase.CloseConnection(myConn);
            }
            catch (Exception myException)
            {
                throw (new Exception(myException.Message + " => " + mCommand.CommandText));
            }
        }
예제 #4
0
        public int ExecuteScalar(SqlCommand mCommand)
        {
            int      temp   = 0;
            DBAccess myBase = new DBAccess();

            try
            {
                SqlConnection myConn = myBase.OpenConnection(connectionString);
                mCommand.Connection = myConn;
                temp = Convert.ToInt32(mCommand.ExecuteScalar().ToString());
                mCommand.Dispose();
                myBase.CloseConnection(myConn);
                return(temp);
            }
            catch (Exception myException)
            {
                throw (new Exception(myException.Message + " => " + mCommand.CommandText));
            }
        }
예제 #5
0
        public DataSet getDataSet(SqlCommand mCommand)
        {
            DBAccess myBase = new DBAccess();

            try
            {
                SqlConnection myConn = myBase.OpenConnection(connectionString);
                mCommand.Connection = myConn;
                SqlDataAdapter myDataAdapter = new SqlDataAdapter(mCommand);
                DataSet        myDataSet     = new DataSet();
                myDataAdapter.Fill(myDataSet);

                myBase.CloseConnection(myConn);
                return(myDataSet);
            }
            catch (Exception myException)
            {
                throw (new Exception(myException.Message + " => " + mCommand.CommandText));
            }
        }
예제 #6
0
        /// <summary>
        /// return a DataSet from SQL Request
        /// </summary>
        public DataSet getDataSet(string strSQL)
        {
            DBAccess myBase = new DBAccess();

            try
            {
                SqlConnection  myConn        = myBase.OpenConnection(connectionString);
                SqlDataAdapter myDataAdapter = new SqlDataAdapter(strSQL, myConn);
                DataSet        myDataSet     = new DataSet();
                myDataAdapter.Fill(myDataSet);

                myDataAdapter.Dispose();
                myBase.CloseConnection(myConn);

                return(myDataSet);
            }
            catch (Exception myException)
            {
                throw (new Exception(myException.Message + " => " + strSQL));
            }
        }
예제 #7
0
        public void ExecuteSQL(string strSQL, params SqlParameter[] Parameters)
        {
            DBAccess myBase = new DBAccess();

            try
            {
                SqlConnection myConn    = myBase.OpenConnection(connectionString);
                SqlCommand    myCommand = new SqlCommand(strSQL, myConn);
                myCommand.Parameters.Clear();
                foreach (SqlParameter par in Parameters)
                {
                    myCommand.Parameters.Add(par);
                }
                myCommand.ExecuteNonQuery();
                myCommand.Dispose();
                myBase.CloseConnection(myConn);
            }
            catch (Exception myException)
            {
                throw (new Exception(myException.Message + " => " + strSQL));
            }
        }
예제 #8
0
        public void ExecuteSQL(string strSQL)
        {
            DBAccess       myBase = new DBAccess();
            SqlConnection  myConn = myBase.OpenConnection(connectionString);
            SqlTransaction tran   = myConn.BeginTransaction();

            try
            {
                SqlCommand myCommand = new SqlCommand(strSQL, myConn);
                myCommand.Transaction = tran;
                myCommand.ExecuteNonQuery();
                tran.Commit();
                myCommand.Dispose();
            }
            catch (Exception myException)
            {
                tran.Rollback();
                throw (new Exception(myException.Message + " => " + strSQL));
            }
            finally
            {
                myBase.CloseConnection(myConn);
            }
        }
예제 #9
0
        public DataSet getDataSet(string strSQL, SqlParameter[] Parameters)
        {
            DBAccess myBase = new DBAccess();

            try
            {
                SqlConnection myConn    = myBase.OpenConnection(connectionString);
                SqlCommand    myCommand = new SqlCommand(strSQL, myConn);
                myCommand.Parameters.Clear();
                foreach (SqlParameter par in Parameters)
                {
                    myCommand.Parameters.Add(par);
                }
                SqlDataAdapter myDataAdapter = new SqlDataAdapter(myCommand);
                DataSet        myDataSet     = new DataSet();
                myDataAdapter.Fill(myDataSet);
                myBase.CloseConnection(myConn);
                return(myDataSet);
            }
            catch (Exception myException)
            {
                throw (new Exception(myException.Message + " => " + strSQL));
            }
        }