1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
private void txtRech_TextChanged(object sender, EventArgs e)
{
try {
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlCommandBuilder cb = new SqlCommandBuilder();
con.ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=mabase;Integrated Security=True";
con.Open();
cmd = new SqlCommand("SELECT * from TClient Where NomClient LIKE @Val OR AdresseClient LIKE @Val OR PostnomClient LIKE @Val", con);
cmd.Parameters.Add("Val", SqlDbType.NVarChar).Value = "%" + txtRech.Text.Trim() + "%";
da = new SqlDataAdapter(cmd);
da.Fill(ds.Tables[0]);
dtgv.DataSource = ds; }
catch (Exception exc) { MessageBox.Show("L'erreur suivante est survenue \n" + exc.Message, "Erreur survenue", MessageBoxButtons.OK, MessageBoxIcon.Error); }
} |
Partager