Esempio n. 1
0
        public int Execute_ReturnID(ConnectionString connString, DbCommandGeneric dbCmd)
        {
            MySqlCommand cmd = new MySqlCommand();

            try
            {
                cmd.Connection = new MySqlConnection(connString.ConnString);
                cmd.Connection.Open();

                cmd.CommandText = dbCmd.DbCommand.CommandText;

                int rowsAffected = cmd.ExecuteNonQuery();

                if (rowsAffected > 0)
                {
                    return(Convert.ToInt32(cmd.LastInsertedId));
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                Uteis.GravarLogErro(ex.TargetSite.Name, ex.Message);
                return(-1);
            }
            finally {
                cmd.Connection.Close();
            }
        }
Esempio n. 2
0
        private DbCommandGeneric GetCommand()
        {
            var dbCmd = new DbCommandGeneric();
            DAO dao   = new DAO();

            dbCmd.DbCommand             = dao.getCommand(ConnectionString);
            dbCmd.DbCommand.CommandText = CommandText;

            return(dbCmd);
        }
Esempio n. 3
0
        public Object ExecuteScalar(DbCommandGeneric dbCmd)
        {
            Object obj;

            try
            {
                obj = dbCmd.DbCommand.ExecuteScalar();
            }
            catch (Exception ex)
            {
                obj = null;
                throw ex;
            }

            if (Connection.DbCommand == null)
            {
                dbCmd.DbCommand.Connection.Close();
            }

            return(obj);
        }
Esempio n. 4
0
        public int Execute(DbCommandGeneric dbCmd)
        {
            int rowsAffected = -1;

            try
            {
                string             commandTextTemp = dbCmd.DbCommand.CommandText;
                List <DbParameter> parametersTemp  = new List <DbParameter>();

                foreach (DbParameter parametro in dbCmd.DbCommand.Parameters)
                {
                    parametersTemp.Add(parametro);
                }

                dbCmd.DbCommand.CommandText = commandTextTemp;
                dbCmd.DbCommand.Parameters.Clear();

                foreach (DbParameter parametro in parametersTemp)
                {
                    dbCmd.DbCommand.Parameters.Add(parametro);
                }

                rowsAffected = dbCmd.DbCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                rowsAffected = 0;
                throw ex;
            }
            finally
            {
                if (Connection.DbCommand == null)
                {
                    dbCmd.DbCommand.Connection.Close();
                }
            }

            return(rowsAffected);
        }