bonsoir,
C'est très bête mais j'ai une form avec une textbox et 2 radiobutton
J'ai crée ma requête SQL pour insérer dans ma table le résultat de ma textbox et de l'un des 2 radiobutton sélectionner
Mais vala, ça enregistre pas.
Je fais pourtant com.executenonquery() mais ça n'enregistre pas la ligne
J'ai oublié quoi ?
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 Private Sub Enregistrer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enregistrer.Click If TextBox1.Text.Trim = "" Then MsgBox("Vous n'avez pas saisie de données à enregistrer") End If If RadioButton1.Checked = False Then If RadioButton2.Checked = False Then MsgBox("Vous devez préciser si le produit est un fruit ou Légume") End If End If Try TextBox1.Text = TextBox1.Text.ToUpper com = New SqlCommand com.Connection = cn com.CommandType = CommandType.Text com.CommandText = "INSERT INTO PRODUIT (NOM_PRO,GROUPE) VALUES (@pro,@grou)" com.Parameters.Add("@pro", SqlDbType.VarChar, 50) com.Parameters("@pro").Value = TextBox1.Text.Trim com.Parameters.Add("@grou", SqlDbType.VarChar, 50) If RadioButton1.Checked = False Then com.Parameters("@grou").Value = RadioButton2.Text.Trim Else com.Parameters("@grou").Value = RadioButton1.Text.Trim End If com.ExecuteNonQuery() Catch ex As Exception MsgBox(ex.Message) End Try Me.Close() End Sub
Merci à vous
Partager