bonjour, j'ai un form (une page de recherche) avec plusieurs critere de recherche 6 criteres, je veux construire ma requête en mettant uniquement les critères remplis, j'ai procédé comme suit :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
        string rqFin = "";
 
            string rubrique = txtChap.Text+txtArt.Text+txtReg.Text+txtParag.Text+txtLigne.Text;
 
            if(!string.IsNullOrEmpty(rubrique))
                rqFin = "where .... like '"+rubrique+"%'";
 
            if (cmbService.SelectedIndex != 0 && !string.IsNullOrEmpty(rubrique))
                rqFin += "AND ....= '" + cmbService.Text + "'";
            else if (cmbService.SelectedIndex != 0 && string.IsNullOrEmpty(rubrique))
                rqFin += "WHERE .... = '" + cmbService.Text + "'";
 
            if ((cmbNatureAO.SelectedIndex != 0 && cmbService.SelectedIndex != 0 && !string.IsNullOrEmpty(rubrique)) || (cmbNatureAO.SelectedIndex != 0 && cmbService.SelectedIndex != 0))
                rqFin = "AND .......... = '" + cmbNatureAO.Text + "'";
            else if (cmbNatureAO.SelectedIndex != 0 && cmbService.SelectedIndex == 0 && string.IsNullOrEmpty(rubrique))
                rqFin += "WHERE ...........= '" + cmbNatureAO.Text + "'";
            else if (cmbNatureAO.SelectedIndex != 0 && cmbService.SelectedIndex == 0 && !string.IsNullOrEmpty(rubrique))
                rqFin += "AND ..............= '" + cmbNatureAO.Text + "'";
 
            if (!string.IsNullOrEmpty(rqFin))
            {
                try
                {
                    SqlDataAdapter adaptR = new SqlDataAdapter("SELECT Rubriques.IDR, ...................... " + rqFin, connection);
                    adaptR.Fill(dt);
                    dgRésultatRecherche.DataSource = dt;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
mais je veux ajouter d'autre requete, la gestion du where et du AND ca serait un peut difficile, une idée ?

Merci