BLL.Metas.Buscar C# (CSharp) Method

Buscar() public method

public Buscar ( int IdBuscado ) : bool
IdBuscado int
return bool
        public override bool Buscar(int IdBuscado)
        {
            DataTable dtMetas = new DataTable();
            DataTable dtMetasDetalle = new DataTable();
            bool retorno = false;

            try
            {
                dtMetas = conexion.ObtenerDatos(string.Format("select * from Metas where MetaId = {0}", IdBuscado));
                if (dtMetas.Rows.Count > 0)
                {
                    this.Descripcion = dtMetas.Rows[0]["Descripcion"].ToString();
                    this.UsuarioId = (int)dtMetas.Rows[0]["UsuarioId"];


                    dtMetasDetalle = conexion.ObtenerDatos(String.Format("select * from MetasDetalle where MetaId = {0}", IdBuscado));

                    LimpiarList();
                    foreach (DataRow row in dtMetasDetalle.Rows)
                    {
                        AgregarMetas((int)row["MetaId"], (int)row["TipoIngresoId"], (double)row["Monto"]);
                    }
                    retorno = true;
                }
            }
            catch (Exception)
            {
                 retorno = false;
            }

            return retorno;
        }

Usage Example

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int Id = 0;
                LlenarDropDownList();

                if (Request.QueryString["Id"] != null)
                {
                    Id = Utilitarios.ToInt(Request.QueryString["Id"].ToString());

                    if (Id > 0)
                    {
                        Metas meta = new Metas();
                        if (!meta.Buscar(Id))
                        {
                            ShowToast("error", "Error", "Registro no encontrado.");
                            Limpiar();
                        }
                        else
                        {
                            MetaIdTextBox.Text = Id.ToString();
                            LlenarMetas(meta);
                        }

                    }
                }
            }
             
        }
All Usage Examples Of BLL.Metas::Buscar