Bonjour,
J’ai fait un code pour charger des données sur un comobox ensuite j’ai fait une requête select,
Le problème c’est que la requête s’effectue bizarrement la première fois, par contre quand je ressaye il fonctionne bien…
PS ; j’ai travaillé avec le mode debug et le point d’arrêt il ya pas d’erreur
merci
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 private void chercher_projet_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); // Chaîne de connexion string connectString = @"Data Source=RENNDXPRDL2596\SQLEXPRESS;Initial Catalog=hafid;Integrated Security=True"; // Objet connection SqlConnection connection = new SqlConnection(connectString); SqlDataAdapter Da_Table_Project = new SqlDataAdapter("SELECT ID_project FROM [Table_Project]", connection); Da_Table_Project.Fill(ds, "Table_Project"); comboBox_cherche.DataSource = ds.Tables["Table_Project"]; comboBox_cherche.DisplayMember = "ID_project"; comboBox_cherche.ValueMember = "ID_project"; } private void button1_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(comboBox_cherche.Text)) { MessageBox.Show("You must fill the name of project", " Reconfigure", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { ma_form_modifyproject.project_name = comboBox_cherche.Text; ma_form_modifyproject.ShowDialog(); } try { // Chaîne de connexion string connectString = @"Data Source=RENNDXPRDL2596\SQLEXPRESS;Initial Catalog=hafid;Integrated Security=True"; // Objet connection SqlConnection connection = new SqlConnection(connectString); // Ouverture connection.Open(); SqlCommand command = new SqlCommand("SELECT * FROM [Table_Project] WHERE ([ID_project]='" + comboBox_cherche.Text + "');", connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ma_form_modifyproject.project_name = reader["ID_project"].ToString(); ma_form_modifyproject.project_category = reader["Project Category"].ToString(); ma_form_modifyproject.datte = reader["kick off date"].ToString(); ma_form_modifyproject.location = reader["Location"].ToString(); } // Fermeture reader reader.Close(); // Fermeture connection connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } }
Partager