ERREUR

ichou -  
Kalissi Messages postés 221 Statut Membre -
Bonjour,
JE SUIS entrain de développer une application mais j'ai rencontre un problème au niveau de l'execution de cette requette


il affiche l'erreur suivant :

There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.

mon programme est

Private Sub Enregistrer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enregistrer.Click
If TBTE.Text <> "" & IsNumeric(TBTE.Text) Then

'********************************* Enregistrer les prix unitaires****************************************************
Dim pug As Decimal = CDec(TBPUG.Text)
Dim pue As Decimal = CDec(TBPUE.Text)
Dim pum As Decimal = CDec(TBPUM.Text)
ajouter_prix_unitaire(DJ.Value, pug, pue, pum)

la fonction et la suivante
Sub ajouter_prix_unitaire(ByVal dt As Date, ByVal pug As Decimal, ByVal pue As Decimal, ByVal pum As Decimal)
Cn.Open()
Dim Requete2 As String = "insert into PrixU (Date_PU,PUG,PUE,PUM) values('" & dt.Date & "'," & (pug) & "," & (pue) & "," & (pum) & ")"
Dim Commande2 As New SqlCommand(Requete2, Cn)
Commande2.ExecuteNonQuery()
Cn.Close()
End Sub

svp j'ai besoin de l'aide

1 réponse

  1. Kalissi Messages postés 221 Statut Membre 20
     
    Bonjour,

    Tu utilise beaucoup d'instructions VB6, je te recommande d'utiliser des
    instructions VB.NET

    IsNumeric !!! VB6
    CDec !!! VB6


    Private Sub Enregistrer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enregistrer.Click

    If TBTE.Text <> "" And IsNumeric(TBTE.Text) Then

    '*********** Enregistrer les prix unitaires**

    Dim pug As Decimal = CDec(TBPUG.Text)
    Dim pue As Decimal = CDec(TBPUE.Text)
    Dim pum As Decimal = CDec(TBPUM.Text)

    ajouter_prix_unitaire(DJ.Value, pug, pue, pum)
    End If

    End Sub

    Utilise plutôt de vrai instructions VB.NET et non des instructions VB6,
    va voir dans les propriétés de ton projet, onglet Références
    Dans la Fenêtre du bas tu devrait trouver (Microsoft.VisualBasic)
    Cette référence te permet d'utiliser des instruction VB6, mais tu apprendra
    de la mauvaise façon à coder en vrai VB.NET

    C'est ton choix.


    Private Sub Enregistrer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enregistrer.Click

    Dim pug As Decimal = 0
    Dim pue As Decimal = 0
    Dim pum As Decimal = 0
    Dim DJ As Date = System.DateTime.Now

    If Not String.IsNullOrEmpty(TBTE.Text) Then
    Dim Nombre As Int32 = 0
    If (Int32.TryParse(TBTE.Text, Nombre)) Then

    '*********** Enregistrer les prix unitaires**
    Dim Nombre1 As Decimal = 0
    Dim Nombre2 As Decimal = 0
    Dim Nombre3 As Decimal = 0

    If Not (String.IsNullOrEmpty(TBPUG.Text)) Then
    If (Decimal.TryParse(TBPUG.Text, Nombre1)) Then
    pug = Nombre1
    End If
    End If

    If Not (String.IsNullOrEmpty(TBPUE.Text)) Then
    If (Decimal.TryParse(TBPUE.Text, Nombre2)) Then
    pue = Nombre2
    End If
    End If

    If Not (String.IsNullOrEmpty(TBPUM.Text)) Then
    If (Decimal.TryParse(TBPUM.Text, Nombre3)) Then
    pum = Nombre2
    End If
    End If

    End If

    Ajouter_prix_unitaire(DJ, pug, pue, pum)

    End If

    End Sub

    Et pour ta requête, utilise un StringBuilder, c'est beaucoup plus facile de ne rien oublier.


    Private Sub Ajouter_prix_unitaire(ByVal dt As Date, ByVal pug As Decimal, ByVal pue As Decimal, ByVal pum As Decimal)

    Cn.Open()

    Dim Requete2 As String = String.Empty
    Dim ReqSQL As New System.Text.StringBuilder

    ReqSQL.Append("INSERT INTO PrixU (Date_PU, PUG, PUE, PUM) VALUES ")
    ReqSQL.Append("('")
    ReqSQL.Append(dt.Date)
    ReqSQL.Append("','")
    ReqSQL.Append(pug)
    ReqSQL.Append("','")
    ReqSQL.Append(pue)
    ReqSQL.Append("','")
    ReqSQL.Append(pum)
    ReqSQL.Append("')")

    Requete2 = ReqSQL.ToString

    Dim Commande2 As New SqlCommand(Requete2, Cn)
    Commande2.ExecuteNonQuery()
    Cn.Close()

    End Sub


    K
    0