コード例 #1
0
 public List<Carro> listarFiltro(Filtro filtro)
 {
     var lista = new List<Carro>();
     using (SqlConnection conn = new SqlConnection())
     {
         conn.ConnectionString = conexao;
         conn.Open();
         String sql = "Select * from dbo.carro where modelo like '%"+ filtro.palavraChave +"%' order by preco desc";
         SqlCommand cmd = new SqlCommand(sql, conn);
         using (SqlDataReader reader = cmd.ExecuteReader())
         {
             while (reader.Read())
             {
                 Carro c = new Carro();
                 c.codigo = (reader["id"]).ToString();
                 c.categoria = (reader["categoria"]).ToString();
                 c.marca = (reader["marca"]).ToString();
                 c.tipo = (reader["tipo"]).ToString();
                 c.modelo = (reader["modelo"]).ToString();
                 c.ano = (reader["ano"]).ToString();
                 c.preco = (reader["preco"]).ToString();
                 c.proprietario = (reader["proprietario"]).ToString();
                 c.placa = (reader["placa"]).ToString();
                 c.cor = (reader["cor"]).ToString();
                 c.obs = (reader["obs"]) != null ? (reader["obs"]).ToString() : "";
                 c.dataAquisicao = (reader["data_aquisicao"]).ToString();
                 lista.Add(c);
             }
         }
     }
     return lista;
 }
コード例 #2
0
 public List<Carro> listarFiltro(Filtro filtro)
 {
     return repo.listarFiltro(filtro);
 }