|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
[C#]Alternative a switch
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.
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek ![]() |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 3306
|
Intanto potresti usare se possibile
Codice:
GetFilteredData(comboScelte.SelectedValue); Codice:
Dictionary<int,string> mappa;//Oppure mappi stringa su stringa mappa[0] = "azienda"; mappa[1] = "targa"; ... GetFilteredData(mappa[comboScelte.SelectedIndex]); //oppure comboScelte.SelectedValue |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 22:16.