public CombustivelColecao ConsultarPorId(int IDCADCOMBUSTIVEL) { try { CombustivelColecao combustivelColecao = new CombustivelColecao(); acessoDadosSqlServer.LimparParametros(); acessoDadosSqlServer.AdicionarParametros("@IDCADCOMBUSTIVEL", IDCADCOMBUSTIVEL); DataTable dataTableCombustivel = acessoDadosSqlServer.ExecutarConsulta(CommandType.StoredProcedure, "uspCADCOMBUSTIVELConsultarPorID"); foreach (DataRow dataRowLinha in dataTableCombustivel.Rows) { Combustivel combustivel = new Combustivel(); combustivel.IDCADCOMBUSTIVEL = Convert.ToInt32(dataRowLinha["IDCADCOMBUSTIVEL"]); combustivel.CADCOMBUSTIVEL = Convert.ToString(dataRowLinha["CADCOMBUSTIVEL"]); combustivelColecao.Add(combustivel); } return(combustivelColecao); } catch (Exception exception) { throw new Exception("Não foi possível consultar o combustível por código. Detalhes: " + exception.Message); } }
//Criando um método atualizar grid private void AtualizarGrid() { CombustivelNegocios combustivelNegocios = new CombustivelNegocios(); CombustivelColecao combustivelColecao = new CombustivelColecao(); combustivelColecao = combustivelNegocios.ConsultarPorNome(textBoxPesquisa.Text); dataGridViewPrincipal.DataSource = null; dataGridViewPrincipal.DataSource = combustivelColecao; dataGridViewPrincipal.Update(); dataGridViewPrincipal.Refresh(); }