public DataSet GetById(SqlConnection oConn, SqlTransaction oTran, Categoria oCategoria)
        {
            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                using (SqlCommand oComm = new SqlCommand())
                {
                    try
                    {
                        DataSet ds = new DataSet();
                        oComm.Connection = oTran != null ? oTran.Connection : oConn;
                        oComm.Transaction = oTran;

                        oComm.CommandType = CommandType.Text;
                        oComm.CommandText = string.Format("SELECT [id],[nombre] FROM {0}.{1} WHERE id=@id", Constants.esquema, Constants.tablaCategorias);

                        oComm.Parameters.AddWithValue("id",oCategoria.Id);

                        adapter.SelectCommand = oComm;
                        adapter.Fill(ds);

                        return ds;
                    }
                    finally
                    {
                    }
                }
            }
        }
        public void Insert(SqlConnection oConn, SqlTransaction oTran, Categoria oCategoria)
        {
            using (SqlCommand oComm = new SqlCommand())
            {
                oComm.Connection = (oTran != null) ? oTran.Connection : oConn;
                oComm.Transaction = oTran;

                oComm.CommandType = CommandType.Text;
                oComm.CommandText = string.Format("INSERT INTO {0}.{1}(nombre) VALUES (@nombre)", Constants.esquema, Constants.tablaCategorias);

                oComm.Parameters.AddWithValue("@nombre", oCategoria.Nombre);                

                oComm.ExecuteNonQuery();
            }
        }
Example #3
0
 public DataSet GetCategoriaById(Categoria oCategoria)
 {
     SqlConnection oConn = new SqlConnection(Constants.connectionString);
     oConn.Open();
     try
     {
         using (CategoriaDataAccess tDataAccess = new CategoriaDataAccess())
         {
             return tDataAccess.GetById(oConn, null, oCategoria);
         }
     }
     finally
     {
         oConn.Close();
     }
 }
 protected void Publicar_Categoria(object sender, EventArgs e)
 {
     if (Page.IsValid) { 
         var oCategoria = new Categoria()
         {                
             Nombre = txt_nombre.Text
         };
         try {  
             new CategoriaBusiness().InsertCategoria(oCategoria);
             lbl_resultado.Text = "Categoria publicada correctamente";
         }
         catch(Exception ex) {
             lbl_resultado.Text = "Hubo un error: "+ex.Message;
         }
     }
     else {  
         lbl_resultado.Text = "Por favor, complete los campos obligatorios del formulario";
     }
 }
Example #5
0
 public void InsertCategoria(Categoria oCategoria)
 {
     SqlConnection oConn = new SqlConnection(Constants.connectionString);
     oConn.Open();
     SqlTransaction oTran = oConn.BeginTransaction();
     try
     {
         using (CategoriaDataAccess tDataAccess = new CategoriaDataAccess())
         {
             tDataAccess.Insert(oConn, oTran, oCategoria);
         }
         oTran.Commit();
     }
     catch (Exception ex)
     {
         oTran.Rollback();
         throw ex;
     }
     finally
     {
         oConn.Close();
         oTran.Dispose();
     }
 }