Bonjour à tous!
Je viens avec (encore) un problème
J'ai une bdd nommée Clients et une bdd Reservation. J'ai un dataGridView1 qui contient le tableau des reservations avec l'id_client.
Mon but est de récupérer le nom du client dans une textBox1 mais lorsque je lance, au niveau de mon while (reader.Read()) j'ai cette erreur :
Une solution?Conversion failed when converting the varchar value 'System.Windows.Forms.DataGridViexSelectedCellCollection' to data type int.
Voici le code:
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 try { string connexionSQL = [Don't worry, elle est bonne mais je ne la mets pas]; string requete = "Select nom from Clients where id_client= '" + dataGridView1.SelectedCells.ToString() + "'"; SqlConnection maConnexionSQLsrv = new SqlConnection(connexionSQL); SqlCommand cmd = new SqlCommand(requete, maConnexionSQLsrv); maConnexionSQLsrv.Open(); SqlDataReader reader = cmd.ExecuteReader(); string nom = ""; int typ = 0; while (reader.Read()) { typ = (int)reader[1]; nom = (string)reader[2]; } if (int.Parse(dataGridView1.SelectedCells.ToString()) == typ) { textBox1.Text = nom; } } catch (SqlException ex) { MessageBox.Show(ex.Message); }
Merci bien!
Partager