Exemple #1
0
        /// <summary>
        /// Altera ou remove um registro
        /// </summary>
        /// <param name="Sql">Síntaxe Sql</param>
        /// <returns></returns>
        public Entity.Retorno Alterar(string Sql)
        {
            SqlConnection oConn = new SqlConnection(ConnectionString);
            SqlCommand oComm = new SqlCommand(Sql, oConn);

            Entity.Retorno retorno = new Entity.Retorno();
            try
            {
                oConn.Open();
                oComm.ExecuteNonQuery();

                retorno.Status = true;
                retorno.Erro = "";
                retorno.Identity = 0;
            }
            catch (Exception e)
            {
                new Log(e);
                retorno.Status = false;
                retorno.Erro = e.Message;
                retorno.Identity = 0;
            }
            finally
            {
                oComm = null;
                oConn.Close();
            }

            return retorno;
        }
Exemple #2
0
        /// <summary>
        /// Insere um novo registro
        /// </summary>
        /// <param name="Sql">Síntaxe Sql</param>
        /// <returns></returns>
        public Entity.Retorno Inserir(string Sql)
        {
            SqlConnection oConn = new SqlConnection(ConnectionString);
            SqlCommand oComm = new SqlCommand(Sql + "; SELECT @@IDENTITY as 'Identity'", oConn);

            SqlDataReader oDr;

            Entity.Retorno retorno = new Entity.Retorno();
            try
            {
                oConn.Open();
                oDr = oComm.ExecuteReader();
                oDr.Read();

                retorno.Status = true;
                retorno.Erro = "";
                retorno.Identity = Convert.ToInt32(oDr["Identity"]);
            }
            catch (Exception e)
            {
                new Log(e);
                retorno.Status = false;
                retorno.Erro = e.Message;
                retorno.Identity = 0;
            }
            finally
            {
                oDr = null;
                oComm = null;
                oConn.Close();
            }

            return retorno;
        }