bonjour,
Je développe une application avec VB.net 2012 et MySql 6, je fait des requètes paramétrées pour dialoguer avec la base de donnée, mais sur une table "article" j'ai des champs du type integer, lors d'une requéte INSERT pour affecter de nouvelles valeurs le workspace me retourne une erreur au "ExecuteNonQuery()" !
voici mon 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
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
 '*************** insert Article    *************
        Dim northwindConnection As New MySqlConnection(SQL_CONNECTION_STRING)
        Dim SqlConnection As MySqlConnection
        SqlConnection = New MySqlConnection()
        Dim sqlCommand As New MySqlCommand
        Dim str_carSql As String
        'Dim strsql As String
        Dim myCommand As MySqlCommand
        'Dim northwindConnection As New MySqlConnection(SQL_CONNECTION_STRING)
        '  Try
        Dim num As Integer
        Dim code_art As String
        Dim lib_article As String
        Dim fam_art As String
        Dim sous_fam_art As String
        Dim num_salle As Integer
        Dim compte_vente As String
        Dim stock_phy As String
        Dim dernier_prix_achat As String
        Dim modif As Date
        Dim immat_douane As String
        Dim questionnaire_insee As String
 
 
        ' num = Convert.ToInt32(Me.TextBox13.Text)
        code_art = Trim(Me.TextBox3.Text)
        lib_article = Trim(Me.TextBox4.Text)
        fam_art = Trim(Me.TextBox5.Text)
        sous_fam_art = Trim(Me.TextBox6.Text)
        num_salle = Convert.ToInt32(Me.TextBox7.Text)
        compte_vente = Trim(Me.TextBox8.Text)
        stock_phy = Trim(Me.TextBox9.Text)
        dernier_prix_achat = Trim(Me.TextBox10.Text)
        modif = Convert.ToDateTime(TextBox11.Text).ToString("yyyy-MM-dd")
        immat_douane = Trim(Me.TextBox12.Text)
        questionnaire_insee = Trim(Me.TextBox13.Text)
 
 
 
 
        str_carSql = "insert into tbl_article (code_art, lib_article, fam_art, sous_fam_art, num_salle, compte_vente, stock_phy, dernier_prix_achat, modif, immat_douane, questionnaire_insee ) values (?p_code_art,?p_lib_article,?p_fam_art,?p_sous_fam_art,?p_num_salle,?p_compte_vente,?p_stock_phy,?p_dernier_prix_achat,?p_modif,?p_immat_douane,?p_ questionnaire_insee )"
 
 
        myCommand = New MySqlCommand(str_carSql, northwindConnection)
 
 
        myCommand.Connection.Open()
 
 
        With myCommand.Parameters
            .Add(New MySqlParameter("?p_code_art", MySqlDbType.VarChar, 45))
            .Add(New MySqlParameter("?p_lib_article", MySqlDbType.VarChar, 45))
            .Add(New MySqlParameter("?p_fam_art", MySqlDbType.VarChar, 45))
            .Add(New MySqlParameter("?p_sous_fam_art", MySqlDbType.VarChar, 45))
            .Add(New MySqlParameter("?p_num_salle", MySqlDbType.Int32, 12))
            .Add(New MySqlParameter("?p_compte_vente", MySqlDbType.VarChar, 45))
            .Add(New MySqlParameter("?p_stock_phy", MySqlDbType.VarChar, 45))
            .Add(New MySqlParameter("?p_dernier_prix_achat", MySqlDbType.VarChar, 45))
            .Add(New MySqlParameter("?p_modif", MySqlDbType.Date, 45))
            .Add(New MySqlParameter("?p_immat_douane", MySqlDbType.VarChar, 45))
            .Add(New MySqlParameter("?p_questionnaire_insee", MySqlDbType.VarChar, 45))
 
 
        End With
 
        'Attribution des valeurs aux paramètres
        With myCommand
            ' .Connection = SqlConnection
            '   .CommandText = str_carSql
            .Parameters("?p_code_art").Value = code_art
            .Parameters("?p_lib_article").Value = lib_article
            .Parameters("?p_fam_art").Value = fam_art
            .Parameters("?p_sous_fam_art").Value = sous_fam_art
            .Parameters("?p_num_salle").Value = num_salle
            .Parameters("?p_compte_vente").Value = compte_vente
            .Parameters("?p_stock_phy").Value = stock_phy
            .Parameters("?p_dernier_prix_achat").Value = dernier_prix_achat
            .Parameters("?p_modif").Value = modif
            .Parameters("?p_immat_douane").Value = immat_douane
            .Parameters("?p_questionnaire_insee").Value = questionnaire_insee
 
 
        End With
 
 
        myCommand.ExecuteNonQuery()
 
        myCommand.Connection.Close()

Faut t'il un paramètre spécial pour les champs du type integer ?


Cdlt,
Philippe