Bonjour,

Je suis actuellement en stage et j'ai quelque soucis. Je n'ai jamais codé en VB.net et donc il se peut que l'erreur soit toute simple.

J'ai un problème lorsque j'essaye d'entrer des données dans une table de la BDD.
Ce que je pense:
-Soit c'est un problème avec les guillemets et les chaines de caractères dans la requête elle même
-Soit il y a un problème avec les type des variables
et dans les deux cas, je ne sais pas comment le régler

Je reçois ce message:
Le format de la chaîne d'entrée est incorrect.
Description : Une exception non gérée s'est produite au moment de l'exécution de la requête Web actuelle. Contrôlez la trace de la pile pour plus d'informations sur l'erreur et son origine dans le code.

Détails de l'exception: System.FormatException: Le format de la chaîne d'entrée est incorrect.
pour la ligne:

Code VB.net : Sélectionner tout - Visualiser dans une fenêtre à part
Ligne 190 :        Obj_Command.CommandText = "INSERT INTO TYPE_ARTICLE (TYPE_ART_IMG, TYPE_ART_LIB, TYPE_ART_DATE_CREATION, TYPE_REF_FOURN, TYPE_REF_CONST, TYPR_ART_GAR_DUREE, TYPE_ART_GAR_MOD, TYPE_ART_DETAILS, TYPE_ART_QTE, TYPE_ART_QTE_LESS, TYPE_ART_QTE_SEC, CAT_ID, TYPE_ART_PA, TYPE_ARTP_PV_HT, TYPE_ART_PV_TTC) VALUES ('" + lienImg + "','" + txtlibelle + "','" + dateDeCreation + "','" + reFourn + "','" + refConstr + "','" + dureeGarant + "','" + modalGarantie + "','" + descArt + "','" + quantStock + "','" + quantAlert + "','" + quantStockSecur + "','" + nomCAT + "','" + prixAchat + "','" + pHT + "','" + pTTC + "')"

Voici mon code VB:
Code VB.net : 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
'déclaration des variables        
Dim txtlibelle As String
        Dim reFourn As String
        Dim refConstr As String
        Dim dureeGarant As String
        Dim modalGarantie As String
        Dim descArt As String
        Dim quantStock As Integer
        Dim quantAlert As Integer
        Dim quantStockSecur As Integer
        Dim dateDeCreation As Date
        Dim Categorie As String
        Dim nomCAT As String
        Dim prixAchat As Decimal
        Dim pHT As Decimal
        Dim pTTC As Decimal
        Dim lienImg As String
 
        info_img.Text = ""
        Info_Alert.Text = ""
        Info_Success.Text = ""
 
        'condition si et seulement si /
 
        If Libelle.Text = "" Or RefFourn.Text = "" Or ddlCateg.SelectedItem.Text = "" Or RefConst.Text = "" Or dureeGarantie.Text = "" Or ddlModalGarantie.SelectedItem.Text = "" Or PrixAchatType.Text = "" Or PrixHT.Text = "" Or PrixTTC.Text = "" Or Not ImageArticle.HasFile Then
            Info_Alert.Text = "Il manque des champs obligatoires !"
            info_img.Text = "Vous n'avez pas sélectionné d'image."
            Response.Write("<script language=""javascript"">window.onload=function(){alert('Veuillez sélectionner une image !')};</script>")
 
        Else
            'Libelle
            txtlibelle = Libelle.Text
 
            'Reference fournisseur
            reFourn = RefFourn.Text
 
            'Référence constructeur
            refConstr = RefConst.Text
 
            'Duree de garantie
            dureeGarant = dureeGarantie.Text
 
            'Modal de garantie
            modalGarantie = ddlModalGarantie.SelectedItem.Text
 
 
            'Description Article
            If DescArticle.InnerText = "" Then
                descArt = "Aucune description"
            Else
                descArt = DescArticle.InnerText
            End If
 
            'Date d'ajout de l'article dans BDD
            dateDeCreation = DateTime.Now.ToString("dd/MM/yyyy")
 
            'Quantité sock
            If QteStock.Text = "" Then
                quantStock = "0"
            Else
                quantStock = QteStock.Text
            End If
 
            'Quantité Alert sock
            If QteAlert.Text = "" Then
                quantAlert = "0"
            Else
                quantAlert = QteAlert.Text
            End If
 
            'Quantité sock securité
            If QteStockSecur.Text = "" Then
                quantStockSecur = "0"
            Else
                quantStockSecur = QteStockSecur.Text
            End If
 
            'Si une catégorie a été selectionnée alors on attribue un nom à la catégorie afin de pouvoir distribuer les image upload dans les fichiers en fonction de sa catégorie
            Categorie = ddlCateg.SelectedItem.Text
            Select Case Categorie
                Case "ACCESSOIRES"
                    nomCAT = "ACCESSOIRES"
                [...]
                Case Else
                    nomCAT = "Autre"
            End Select
 
            Dim path As String = Server.MapPath("~/Articles/" + nomCAT + "/")
            Dim fileOK As Boolean = False
 
 
            Dim fileExtension As String
            fileExtension = System.IO.Path. _
                GetExtension(ImageArticle.FileName).ToLower()
            Dim allowedExtensions As String() = _
                {".jpg", ".jpeg", ".png"}
            For i As Integer = 0 To allowedExtensions.Length - 1
                If fileExtension = allowedExtensions(i) Then
                    fileOK = True
                End If
            Next
 
            lienImg = "~/Articles/" + nomCAT + "/" + RefFourn.Text + fileExtension
 
            If fileOK Then
                Try
                    ImageArticle.PostedFile.SaveAs(path & _
                         RefFourn.Text & fileExtension)
                    info_img.Text = "L'image a été upload dans le dossier: " + path + " <br/>" + lienImg
                Catch ex As Exception
                    info_img.Text = "L'image n'a pas été upload ! "
                End Try
            Else
                info_img.Text = "Les fichiers de ce type ne sont pas acceptés. (seul les .jpg, .jpeg et .png sont autorisés !)"
            End If
 
 
            'Prix à l'achat du type d'article
            prixAchat = PrixAchatType.Text
 
            'Prix HT
            pHT = PrixHT.Text
 
            'Prix TTC
            pTTC = PrixTTC.Text
 
            'Connexion à la BDD
            access_connexion()
 
            'Instancier un objet Command
            Obj_Command = New OleDbCommand()
 
            'Initialiser l'objet Command
            Obj_Command.Connection() = laConnection
            Obj_Command.CommandText = "INSERT INTO TYPE_ARTICLE (TYPE_ART_IMG, TYPE_ART_LIB, TYPE_ART_DATE_CREATION, TYPE_REF_FOURN, TYPE_REF_CONST, TYPR_ART_GAR_DUREE, TYPE_ART_GAR_MOD, TYPE_ART_DETAILS, TYPE_ART_QTE, TYPE_ART_QTE_LESS, TYPE_ART_QTE_SEC, CAT_ID, TYPE_ART_PA, TYPE_ARTP_PV_HT, TYPE_ART_PV_TTC) VALUES ('" + lienImg + "','" + txtlibelle + "','" + dateDeCreation + "','" + reFourn + "','" + refConstr + "','" + dureeGarant + "','" + modalGarantie + "','" + descArt + "','" + quantStock + "','" + quantAlert + "','" + quantStockSecur + "','" + nomCAT + "','" + prixAchat + "','" + pHT + "','" + pTTC + "')"
            Obj_Reader = Obj_Command.ExecuteReader()
 
            Obj_Reader.Close()
            access_deconnexion()
 
            'message success
            Info_Success.Text = "L'article a bien été enregistré dans la BDD"
 
 
        End If

Je vous remercie par avance pour vos réponses.

Artas