Ciao a tutti
Ho scritto questo codice che mi serve per ottenere alcuni dati in base ad un filtro:
Codice:
private void GetFilteredData(string tipo)
{
DbClass db = new DbClass();
try
{
string select = "SELECT * FROM vetture WHERE " + tipo + " LIKE '?filtro' ORDER BY " + tipo + " ";
MysqlDataAdapter mda = new MySqlDataAdapter(select, db.ActiveConnection);
DataTable dt = new DataTable();
mda.Fill(dt);
//codice per visualizzare i dati blablabla
}
catch(MysqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
db.CloseConnection(db.ActiveConnection);
}
}
private void btnFilter_Click(objext sender, EventArgs e)
{
string tipo = "";
switch (comboScelte.SelectedIndex)
{
case 0:
tipo = "azienda";
GetFilteredData(tipo);
break;
case 1:
tipo = "targa";
GetFilteredData(tipo);
break;
default:
MessageBox.Show("Nessun filtro selezionato");
break;
}
}
Attendo suggerimenti
Grazie mille.
RaouL.