public List <VeiculoDTO> ConsultarVeiculoFiltro(string placa) { string script = $"SELECT * FROM Veiculo WHERE CPF like '%{placa}%'"; List <MySqlParameter> parms = new List <MySqlParameter>(); Database db = new Database(); MySqlDataReader reader = db.ExecuteSelectScript(script, parms); List <VeiculoDTO> Veiculo = new List <VeiculoDTO>(); while (reader.Read()) { FuncionarioDTO dados = new FuncionarioDTO(); dados.idBVeiculo = reader.GetInt32("idVeiculo"); dados.modelo = reader.GetString("modelo"); dados.marca = reader.GetString("marca"); dados.cor = reader.GetInt("placa"); Veiculo.Add(dados); } reader.Close(); return(Veiculo); }
public List <Pacote> Listar() { MySqlConnection conexao = new MySqlConnection(_strConexao); conexao.Open(); string sql = "SELECT * FROM compra"; MySqlCommand comando = new MySqlCommand(sql, conexao); MySqlDataReader reader = comando.ExecuteReader(); List <Pacote> lista = new List <Pacote>(); while (reader.Read()) { Compra compra = new Compra(); compra.Id = reader.GetInt32("id"); if (!reader.IsDBNull(reader.GetOrdinal("IdUsuario"))) { compra.IdUsuario = reader.GetInt("IdUsuario"); } if (!reader.IsDBNull(reader.GetOrdinal("IdPacote"))) { pacote.IdPacote = reader.GetInt32("IdPacote"); } if (!reader.IsDBNull(reader.GetOrdinal("Valor"))) { pacote.Valor = reader.GetDouble("Valor"); } if (!reader.IsDBNull(reader.GetOrdinal("Total"))) { pacote.Total = reader.GetDouble("Total"); } if (!reader.IsDBNull(reader.GetOrdinal("Pagamento"))) { pacote.Pagamento = reader.GetString("Pagamento"); } lista.Add(compra); } conexao.Close(); return(lista); }
static void Main(string[] args) { Console.WriteLine("Connect to MySql"); using (connection) { try{ connection.Open(); System.Console.WriteLine("Koneksi: " + connection.State.Tostring() + Enviroment.NewLine); MySqlCommand command = connection.CreateCommand(); command.CommandText = System.Data.CommandType.Text; command.CommandText = "Select * from guitar"; MySqlDataReader reader = command.ExecuteReader(); var data = "[type]\t[brand]\t[bodytype]\t[price]\n"; if (reader.Hashrow) { while (reader.Read()) { data += reader.GetString(0) + reader.Getstring(1) + reader.GetString(2) + reader.GetInt(3); +Environment.NewLine; } Console.WriteLine(data); } else { Console.WriteLine("Data Unknown") } reader.Close(); connection.Close(); System.Console.WriteLine("Koneksi: " + connection.State.Tostring() + Enviroment.NewLine); } catch (My.Sql.Data.MySqlClient.MySqlException ex) { System.Console.WriteLine("eror " + ex.Message.Tostring()); Console.Readkey(); } finally{ System.Console.WriteLine("Exit..."); Console.Readkey(); } } }