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 33 34 35 36 37 38 39 40 41
| private void comboBenef_TextChanged(object sender, EventArgs e)
{
string req;
comboBenef.Items.Clear();
connectionsql connexion = new connectionsql();
if (comboBenef.Text == "")
{
req = "select * from tab_beneficiaire";
}
else
{
req = "select * from tab_beneficiaire where designation like @Beneficiaire";
connexion.AddParametre("@Beneficiaire", SqlDbType.NVarChar, "%" + comboBenef.Text + "%");
}
try
{
connexion.req = req;
connexion.CreateReq();
connexion.ExecuteReader();
if (connexion.rdr.HasRows)
{
while (connexion.rdr.Read())
{
Item itm = new Item();
itm.Text = Convert.ToString(connexion.rdr.GetValue(1));
itm.Value = connexion.rdr.GetValue(0);
comboBenef.Items.Add(itm);
}
}
connexion.rdr.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connexion.Deconnection();
}
} |