Bonjour à tous, je suis nouveau sur le forum et dans le cadre de mon stage je dois réaliser une application web en asp au langage C#. J'ai un petit problème avec deux listbox généré via une base de données SQL. J'ai une table Customer (Client en français) avec deux champs : ID_Customer et Name_Customer, j'arrive à les afficher dans mes deux listbox, mais le problème étant que je voudrais faire une "mise à jour" (je sais pas si on le dit comme ça) de mes listbox, je m'explique lorsque je sélectionne un client (exemple : peugeot), cela m'affiche l'id correspondant soit dans mon problème l'ID 6. Or je ne sais pas du tout comment faire, si vous avez une idée, je suis preneur. Merci à vous.

Mon code Update.aspx.cs :

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
public partial class Update : System.Web.UI.Page
{
    SqlConnection myConnection;
    SqlCommand myCmdUpdate = new SqlCommand();
 
    protected void Page_Load(object sender, EventArgs e)
    {
        myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\MARK IV\Documents\Non-Conformance.mdf;
        Integrated Security=True;Connect Timeout=30;User Instance=True");
        myCmdUpdate.Connection = myConnection;
 
        //Label caché
 
        lblUpdateCustomer.Text = string.Empty;
        lblError.Text = string.Empty;
        lblUpdateProductFamily.Text = string.Empty;
        lblErrorProductFamily.Text = string.Empty;
    }
 
    protected void btnUpdateCustomer_Click(object sender, EventArgs e)
    {
        if (txtCustomer.Text == string.Empty)
        {
            lblError.Text = "Please select a Update Customer !";
            return;
        }
 
        try
        {
 
            //Connexion à la bdd
            myConnection.Open();
 
            //Requête SQL :
            string requete = "UPDATE [Customer] SET Name_Customer = @Customer WHERE ID_Customer = @IDCustomer";
            using (SqlCommand myCmdUpdate = new SqlCommand(requete, myConnection))
            {
                myCmdUpdate.Parameters.AddWithValue("@IDCustomer", lstIDCustomer.SelectedItem.Value);
                myCmdUpdate.Parameters.AddWithValue("@Customer", this.txtCustomer.Text);
 
                myCmdUpdate.ExecuteNonQuery();
 
 
                lblUpdateCustomer.Text = "Modification réussie";                
            }
 
 
        }
        catch (SqlException se)
        {
            lblUpdateCustomer.Text = (se.ToString());
            lblUpdateCustomer.Text = "Modification échoué";
        }
        finally
        {
            //Ferme la connexion à la bdd
            myConnection.Close();
        }
    }
    protected void btnInsertCustomer_Click(object sender, EventArgs e)
    {
        if (txtCustomer.Text == string.Empty)
        {
            lblError.Text = "Please insert a new Customer !";
            return;
        }
 
        try
        {
 
            //Connexion à la bdd
            myConnection.Open();
 
            //Requête SQL :
            string requete = "INSERT INTO Customer (Name_Customer) VALUES (@NameCustomer)";
            using (SqlCommand myCmdUpdate = new SqlCommand(requete, myConnection))
            {
 
                myCmdUpdate.Parameters.AddWithValue("@NameCustomer", this.txtCustomer.Text);
 
                myCmdUpdate.ExecuteNonQuery();
 
 
                lblUpdateCustomer.Text = "Insertion réussie";
            }
 
 
        }
        catch (SqlException se)
        {
            lblUpdateCustomer.Text = (se.ToString());
            lblUpdateCustomer.Text = "Insertion a échoué";
        }
        finally
        {
            //Ferme la connexion à la bdd
            myConnection.Close();
        }
    }
    protected void btnDeleteCustomer_Click(object sender, EventArgs e)
    {
        try
        {
 
            //Connexion à la bdd
            myConnection.Open();
 
            //Requête SQL :
            string requete = "DELETE FROM Customer WHERE ID_Customer = @IDCustomer";
            using (SqlCommand myCmdUpdate = new SqlCommand(requete, myConnection))
            {
 
                myCmdUpdate.Parameters.AddWithValue("@IDCustomer", lstIDCustomer.SelectedItem.Value);
 
                myCmdUpdate.ExecuteNonQuery();
 
 
                lblUpdateCustomer.Text = "Suppression réussie";                
            }
 
 
        }
        catch (SqlException se)
        {
            lblUpdateCustomer.Text = (se.ToString());
            lblUpdateCustomer.Text = "Suppression a échoué";
        }
        finally
        {
            //Ferme la connexion à la bdd
            myConnection.Close();
        }
    }
    protected void btnUpdateProductFamily_Click(object sender, EventArgs e)
    {
        if (txtUpdateProductFamily.Text == string.Empty)
        {
            lblErrorProductFamily.Text = "Please select a Update Product Family !";
            return;
        }
 
        try
        {
 
            //Connexion à la bdd
            myConnection.Open();
 
            //Requête SQL :
            string requete = "UPDATE [ProductFamily] SET Name_ProductFamily = @productFamily WHERE ID_ProductFamily = @IDProductFamily";
            using (SqlCommand myCmdUpdate = new SqlCommand(requete, myConnection))
            {
                myCmdUpdate.Parameters.AddWithValue("@IDProductFamily", lstIDProductFamily.SelectedItem.Value);
                myCmdUpdate.Parameters.AddWithValue("@productFamily", this.txtUpdateProductFamily.Text);
 
                myCmdUpdate.ExecuteNonQuery();
 
 
                lblUpdateProductFamily.Text = "Modification réussie";                
            }
 
 
        }
        catch (SqlException se)
        {
            lblUpdateProductFamily.Text = (se.ToString());
            lblUpdateProductFamily.Text = "Modification échoué";
        }
        finally
        {
            //Ferme la connexion à la bdd
            myConnection.Close();
        }
    }
 
    protected void btnInsertProductFamily_Click(object sender, EventArgs e)
    {
        {
            if (txtUpdateProductFamily.Text == string.Empty)
            {
                lblErrorProductFamily.Text = "Please insert a new Product Family";
                return;
            }
 
            try
            {
 
                //Connexion à la bdd
                myConnection.Open();
 
                //Requête SQL :
                string requete = "INSERT INTO ProductFamily (Name_ProductFamily) VALUES (@NameProductFamily)";
                using (SqlCommand myCmdUpdate = new SqlCommand(requete, myConnection))
                {
 
                    myCmdUpdate.Parameters.AddWithValue("@NameProductFamily", this.txtUpdateProductFamily.Text);
 
                    myCmdUpdate.ExecuteNonQuery();
 
 
                    lblUpdateProductFamily.Text = "Insertion réussie";
                }
 
 
            }
            catch (SqlException se)
            {
                lblErrorProductFamily.Text = (se.ToString());
                lblErrorProductFamily.Text = "Insertion a échoué";
            }
            finally
            {
                //Ferme la connexion à la bdd
                myConnection.Close();
            }
        }
    }
 
    protected void btnDeleteProductFamily_Click(object sender, EventArgs e)
    {
        try
        {
            //Connexion à la bdd
            myConnection.Open();
 
            //Requête SQL :
            string requete = "DELETE FROM ProductFamily WHERE ID_ProductFamily = @IDProductFamily";
            using (SqlCommand myCmdUpdate = new SqlCommand(requete, myConnection))
            {
 
                myCmdUpdate.Parameters.AddWithValue("@IDProductFamily", lstIDProductFamily.SelectedItem.Value);
 
                myCmdUpdate.ExecuteNonQuery();
 
 
                lblUpdateProductFamily.Text = "Suppression réussie";                
            }
 
 
        }
        catch (SqlException se)
        {
            lblUpdateProductFamily.Text = (se.ToString());
            lblUpdateProductFamily.Text = "Suppression a échoué";
        }
        finally
        {
            //Ferme la connexion à la bdd
            myConnection.Close();
        }
    }
 
    protected void lstIDCustomer_SelectedIndexChanged(object sender, EventArgs e)
    {
 
    }
}