Beispiel #1
0
        public string ExecScalar(SqlCommand sCommand)
        {
            SqlConnection sConnection = new ClassFuncoes().GetConexaoBD();
            string        sRetorno    = "";

            try
            {
                sConnection.Open();
                sCommand.Connection = sConnection;
                sCommand.Prepare();
                sRetorno = sCommand.ExecuteScalar().ToString();
            }
            catch
            {
            }
            finally
            {
                if (sConnection.State == ConnectionState.Open)
                {
                    sConnection.Close();
                }
            }

            return(sRetorno);
        }
Beispiel #2
0
        public string ExecNonQuery(SqlCommand sCommand)
        {
            string sRetorno = "";

            SqlConnection sConnection = new ClassFuncoes().GetConexaoBD();

            try
            {
                sConnection.Open();
                sCommand.Connection = sConnection;
                sCommand.Prepare();
                sCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                sRetorno = ex.Message;
            }
            finally
            {
                if (sConnection.State == ConnectionState.Open)
                {
                    sConnection.Close();
                }
            }

            return(sRetorno);
        }
Beispiel #3
0
        public DataTable ExecReader(SqlCommand sCommand)
        {
            SqlConnection sConnection = new ClassFuncoes().GetConexaoBD();
            DataTable     tblRetorno  = new DataTable();

            try
            {
                sConnection.Open();
                sCommand.Connection = sConnection;
                sCommand.Prepare();
                SqlDataReader rReader = sCommand.ExecuteReader(CommandBehavior.CloseConnection);
                tblRetorno.Load(rReader);
            }
            catch
            {
            }
            finally
            {
                if (sConnection.State == ConnectionState.Open)
                {
                    sConnection.Close();
                }
            }

            return(tblRetorno);
        }
Beispiel #4
0
        public string ExecNonQuery(SqlCommand sCommand, SqlCommand sCommand1)
        {
            string sRetorno = "";

            SqlConnection sConnection = new ClassFuncoes().GetConexaoBD();

            sConnection.Open();

            sCommand.Connection  = sConnection;
            sCommand1.Connection = sConnection;

            sCommand.Prepare();
            sCommand1.Prepare();

            SqlTransaction objTrans = sConnection.BeginTransaction();

            sCommand.Transaction  = objTrans;
            sCommand1.Transaction = objTrans;

            try
            {
                sCommand.ExecuteNonQuery();
                sCommand1.ExecuteNonQuery();

                objTrans.Commit();
            }
            catch (Exception ex)
            {
                objTrans.Rollback();
                sRetorno = ex.Message;
            }
            finally
            {
                if (sConnection.State == ConnectionState.Open)
                {
                    sConnection.Close();
                }
            }

            return(sRetorno);
        }