IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

probléme d'erreur à l'éxécution d'un formulaire insert [Débutant]


Sujet :

VB.NET

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2012
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2012
    Messages : 100
    Points : 27
    Points
    27
    Par défaut probléme d'erreur à l'éxécution d'un formulaire insert
    bonjour à tous,

    quand l'utilisateur clicke sur enregistrer les données saisie dans le formulaires sont ajouter a une table de ma base de données 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
    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
    -----
            'variable déclaration
            '------------------------------
     
            Dim objCommand As SqlCommand
     
            Dim objParam As SqlParameter
     
            Dim dt_KeywordsID As DataTable = New DataTable("detail_piece")
     
            Dim dtc_KeywordsID As DataColumn
     
            Dim myConnection As SqlConnection = New SqlConnection("data source=UC033\DEV;integrated security=SSPI;initial catalog=BUDGET2")
     
            '-------------------------------------
     
            '   Create a connection to SQL Server
     
            '-------------------------------------        
     
            objCommand = New SqlCommand("spd_detail_piece_insert", myConnection)
     
            objCommand.CommandType = CommandType.StoredProcedure
     
            objCommand.Connection.Open()
     
            '-------------------------------------
     
            '   Create parameters for sp
     
            '-------------------------------------  
     
     
            objParam = objCommand.Parameters.Add("@id_nom_piece", SqlDbType.Int)
            objParam.Value = lst_NomPiece.SelectedValue
     
            objParam = objCommand.Parameters.Add("@id_profil", SqlDbType.Int)
            objParam.Value = lst_profil.SelectedValue
     
            objParam = objCommand.Parameters.Add("@id_contrat", SqlDbType.Int)
            objParam.Value = lst_contrat.SelectedValue
     
            objParam = objCommand.Parameters.Add("@id_projet", SqlDbType.Int)
            objParam.Value = lst_projet.SelectedValue
     
            objParam = objCommand.Parameters.Add("@num_piece", SqlDbType.Int)
            objParam.Value = txt_NumPiece.Text
     
            objParam = objCommand.Parameters.Add("@caracteristiques_imposees", SqlDbType.Bit)
            objParam.Value = CheckBox1.Checked
     
            objParam = objCommand.Parameters.Add("@nom_responsable", SqlDbType.VarChar)
            objParam.Value = txt_NomResponsable.Text
     
            objParam = objCommand.Parameters.Add("@date_livraison_souhaitee", SqlDbType.DateTime)
            objParam.Value = txt_ConfirmationDateLivraison.Text
     
            objParam = objCommand.Parameters.Add("@service_concerne", SqlDbType.VarChar)
            objParam.Value = txt_ServiceConcerne.Text
     
            objParam = objCommand.Parameters.Add("@contrat_existant", SqlDbType.Bit)
            objParam.Value = CheckBox3.Checked
     
            objParam = objCommand.Parameters.Add("@mission_forfait", SqlDbType.Bit)
            objParam.Value = CheckBox5.Checked
     
            objParam = objCommand.Parameters.Add("@paris_province", SqlDbType.VarChar)
            objParam.Value = txt_pairs_province.Text
     
            objParam = objCommand.Parameters.Add("@volume_estime_j_h", SqlDbType.Int)
            objParam.Value = txt_Volume_j_h.Text
     
            objParam = objCommand.Parameters.Add("@montant_astrainte", SqlDbType.Int)
            objParam.Value = txt_astrainte.Text
     
            objParam = objCommand.Parameters.Add("@montant_deplacement", SqlDbType.Int)
            objParam.Value = txt_deplacement.Text
     
            objParam = objCommand.Parameters.Add("@date_debut_prestation", SqlDbType.DateTime)
            objParam.Value = txt_ConfirmationDateDeb.Text
     
            objParam = objCommand.Parameters.Add("@date_fin_prestation", SqlDbType.DateTime)
            objParam.Value = txt_ConfirmationDateFin.Text
     
            objParam = objCommand.Parameters.Add("@TJM", SqlDbType.Int)
            objParam.Value = txt_TJM.Text
     
            '-------------------------------------
     
            '   Prepare table as parameter
     
            '------------------------------------- 
     
            dtc_KeywordsID = New DataColumn()
            dtc_KeywordsID.ColumnName = "id_detail_piece"
            dt_KeywordsID.Columns.Add(dtc_KeywordsID)
            '-------------------------------------
     
            '   Store procedure execution
     
            '-------------------------------------  
     
            objCommand.ExecuteNonQuery()
     
     
     
            '-------------------------------------
            '   Close the connexion object
            '-------------------------------------  
     
            objCommand.Connection.Close()
     
     
            '---------------------------
            'message de confirmation
            '---------------------------
     
            Session("lblmessage") = "l'ajout est bien effectuer"
            Response.Redirect("message.aspx")
    end sub
    j'ai une erreur a l'exécution qui est la suivante:
    the insert statement conflicted with the foreign key constraint "FK_detail_piece_projet" the conflict occured in database "BUDGET2" table "dbo.projet" column "id_projet"
    the statement as been terminated
    je ne sais pas si quelqu'un peut m'aider a annuller cette erreur?
    si oui merci d'avanc de me dire comment faire

  2. #2
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 176
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 176
    Points : 25 118
    Points
    25 118
    Par défaut
    tu as une relation entre tes tables
    pour insérer des données dans la table fille, les données de la relation doivent exister dans la table mère

  3. #3
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2012
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2012
    Messages : 100
    Points : 27
    Points
    27
    Par défaut
    oui d'accord mais pour moi c'est fait ça

    mais la clé étrangére detail_piece_projet n'existe pas et il me parle de cela dans l'erreur je ne compren pas bien...

  4. #4
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2012
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mars 2012
    Messages : 100
    Points : 27
    Points
    27
    Par défaut
    probléme résolu merci

    je m'étais tromper dans l'insert dans l'ordre...
    bonne fin de journée

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 6
    Dernier message: 24/04/2013, 17h14
  2. [Flex4] Problème Focus ? - Erreur Error #1009 sur Formulaires
    Par tlafont2607 dans le forum Flex
    Réponses: 1
    Dernier message: 18/03/2013, 15h04
  3. problème affichage erreurs dans formulaire
    Par polo42 dans le forum Django
    Réponses: 1
    Dernier message: 16/12/2012, 21h14
  4. erreur de formulaire, insertion BD
    Par bachilbouzouk dans le forum ASP
    Réponses: 7
    Dernier message: 12/04/2005, 08h22
  5. [OpenGL] Problème de Vitesse d'éxécution
    Par stick059 dans le forum OpenGL
    Réponses: 9
    Dernier message: 19/11/2004, 13h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo