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

ASP.NET Discussion :

probleme exception sql exception


Sujet :

ASP.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    49
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2010
    Messages : 49
    Par défaut probleme exception sql exception
    bonjour,
    je realise une application web sous visual studio 2008 en Asp.net vb, et dans une page j'ai un formulaire que l'utilisateur doit remplir.

    lors de l'execution de mon application, je saisit le formulaire, lorsque je clique sur ajouter un message d'erreur apparait comme celui ci-dessous :

    Exception SQL exception n'a pas été gérée par le code utilisateur

    l'instruction insert est en conflit avec la contrainte foreign key "FK_EmployePD_IDPDP_276EDEB3". Le conflit s'est produit dans la base de données "suiviPDP", table "Dbo.'pdp'. l'instruction a été arrêtée.
    voici la procedure visée au niveau du ".insert":
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    Protected Sub RecordIntervenant(ByVal idIntervenant As String)
            With SqlDataSourceIntervenantPDP
                With .InsertParameters
                    .Clear()
                    .Add("idIntervenant", idIntervenant)
                    .Add("idPDP", ParamidPDP.Text)
                    .Add("PriseConnaissance", "0")
                    .Add("AjoutePar", Page.User.Identity.Name)
                End With
                .Insert()
                .InsertParameters.Clear()
            End With
        End Sub

  2. #2
    Membre chevronné Avatar de jacky01
    Profil pro
    Développeur .NET
    Inscrit en
    Juin 2007
    Messages
    537
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juin 2007
    Messages : 537
    Par défaut
    Bonjour

    Le problème ne vient pas du code vb ou asp mais des valeurs inséré en base.
    En gros il te dit que l'enregistrement que tu essai d'insérer ne va pas car il ne respect pas les contrainte de clé étrangère.

    Donc vérifie que les valeurs que tu insert sont correct sinon regarde du coté de la structure de ta base.

  3. #3
    Membre averti
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    49
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2010
    Messages : 49
    Par défaut
    bonjour,
    merci pour ses renseignements, j'ai recherché une erreur de declaration de type ou autre et je n'ai rien trouvé a votre avis les probleme peut venir d'autre chose ?

    si pouvez jeter un oeil sur mon code sa serai sympa, car l'erreur doit etre benine.

    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
    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
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
     
    <%@ Control
        Language="VB"
        AutoEventWireup="false"
        CodeFile="IntervenantPDP.ascx.vb"
        Inherits="Modules_IntervenantPDP" %>
    <%@ Register
        Src="~/Modules/Intervenant.ascx"
        TagName="Intervenant"
        TagPrefix="uc1" %>
    <asp:Label
        ID="ParamidIntervenant"
        runat="server"
        Visible="False" />
    <asp:Label
        ID="ParamidPDP"
        runat="server"
        Visible="false" />
    <asp:Panel
        ID="PanelIntervenantPDP"
        Visible="true"
        runat="server"
        Width="100%">
        <asp:DropDownList
            ID="DropDownListIntervenant"
            runat="server"
            DataSourceID="SqlDataSourceIntervenantRestant"
            DataTextField="NomPrenom"
            DataValueField="idIntervenant"
            Width="200px"
            OnDataBound="DropDownListIntervenant_DataBound">
        </asp:DropDownList>
        <asp:LinkButton
            ID="LinkButton_AddIntervenant"
            runat="server"
            OnClick="LinkButton_AddIntervenant_Click">Ajouter</asp:LinkButton>
        <asp:LinkButton
            ID="LinkButton_NewIntervenant"
            runat="server"
            OnClick="LinkButton_NewIntervenant_Click">Nouveau</asp:LinkButton>
        <asp:DropDownList
            ID="DropDownListidEntreprise"
            runat="server"
            DataSourceID="SqlDataSourceEntreprise"
            DataTextField="IdEntreprise"
            DataValueField="idEntreprise"
            Visible="False">
        </asp:DropDownList>
        <asp:GridView
            ID="GridViewIntervenantPDP"
            runat="server"
            AllowSorting="True"
            AutoGenerateColumns="False"
            DataKeyNames="idIntervenant,idPDP"
            DataSourceID="SqlDataSourceIntervenantPDP"
            OnRowEditing="GridViewIntervenantPDP_RowEditing"
            EmptyDataText="(Aucun intervenant autorisé)"
            Width="100%"
            OnRowDeleted="GridViewIntervenantPDP_RowDeleted">
            <Columns>
                <asp:TemplateField
                    HeaderText="Nom"
                    SortExpression="Nom">
                    <ItemTemplate>
                        <asp:HyperLink
                            runat="server"
                            ID="HyperLinkDetails1"
                            NavigateUrl='<%# Eval("idIntervenant", "~/Intervenant.aspx?Mode=View&idIntervenant={0}") %>'>
                            <asp:Label
                                ID="Label2"
                                runat="server"
                                Text='<%# Bind("Nom") %>' />
                        </asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField
                    HeaderText="Prénom"
                    SortExpression="Prenom">
                    <ItemTemplate>
                        <asp:HyperLink
                            runat="server"
                            ID="HyperLinkDetails2"
                            NavigateUrl='<%# Eval("idIntervenant", "~/Intervenant.aspx?Mode=View&idIntervenant={0}") %>'>
                            <asp:Label
                                ID="Label3"
                                runat="server"
                                Text='<%# Bind("Prenom") %>' />
                        </asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField
                    ShowHeader="False"
                    SortExpression="PriseConnaissance"
                    HeaderText="Signature">
                    <ItemTemplate>
                        <asp:CheckBox
                            runat="server"
                            ID="CheckBoxPriseConnaissance"
                            OnCheckedChanged="CheckBoxPriseConnaissance_CheckedChanged"
                            Checked='<%# Bind("PriseConnaissance") %>' />
                    </ItemTemplate>
                    <ItemStyle
                        Width="120px"
                        HorizontalAlign="Center" />
                    <HeaderStyle
                        HorizontalAlign="Center" />
                </asp:TemplateField>
                <asp:TemplateField
                    HeaderText="Ajouté par"
                    InsertVisible="False"
                    SortExpression="AjoutePar">
                    <ItemStyle
                        Width="70px"
                        Font-Size="0.8em" />
                    <ItemTemplate>
                        <asp:Label
                            ID="Label1"
                            runat="server"
                            Text='<%# LoginMod(Eval("AjoutePar").tostring) %>' />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton
                            ID="IBDetails"
                            runat="server"
                            PostBackUrl='<%# Eval("idIntervenant", "~/Intervenant.aspx?Mode=View&idIntervenant={0}") %>'
                            SkinID="Details" />
                    </ItemTemplate>
                    <ItemStyle
                        Width="20px" />
                </asp:TemplateField>
                <asp:TemplateField
                    ShowHeader="False">
                    <ItemTemplate>
                        <asp:ImageButton
                            ID="IBSuppr"
                            runat="server"
                            OnClientClick='<%# "return confirm(""Etes-vous sur de vouloir détacher " & Eval("NomPrenom").ToString & " de ce PDP ?"");" %>'
                            CommandName="Delete"
                            SkinID="Delete" />
                    </ItemTemplate>
                    <ItemStyle
                        Width="20px" />
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </asp:Panel>
    <asp:Panel
        ID="PanelIntervenantPDPReadOnly"
        runat="server"
        Width="100%">
        <asp:GridView
            ID="GridView1"
            runat="server"
            AllowSorting="True"
            AutoGenerateColumns="False"
            DataKeyNames="idIntervenant,idPDP"
            DataSourceID="SqlDataSourceIntervenantPDP"
            OnRowEditing="GridViewIntervenantPDP_RowEditing"
            EmptyDataText="(Aucun intervenant autorisé)"
            Width="100%"
            OnRowDeleted="GridViewIntervenantPDP_RowDeleted">
            <Columns>
                <asp:TemplateField
                    HeaderText="Nom"
                    SortExpression="Nom">
                    <ItemTemplate>
                        <asp:HyperLink
                            runat="server"
                            ID="HyperLinkDetails4"
                            NavigateUrl='<%# Eval("idIntervenant", "~/Intervenant.aspx?Mode=View&idIntervenant={0}") %>'>
                            <asp:Label
                                ID="Label2"
                                runat="server"
                                Text='<%# Bind("Nom") %>'></asp:Label></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField
                    HeaderText="Prénom"
                    SortExpression="Prenom">
                    <ItemTemplate>
                        <asp:HyperLink
                            runat="server"
                            ID="HyperLinkDetails5"
                            NavigateUrl='<%# Eval("idIntervenant", "~/Intervenant.aspx?Mode=View&idIntervenant={0}") %>'>
                            <asp:Label
                                ID="Label3"
                                runat="server"
                                Text='<%# Bind("Prenom") %>'></asp:Label></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField
                    ShowHeader="False"
                    SortExpression="PriseConnaissance"
                    HeaderText="Signature">
                    <ItemStyle
                        Width="120px"
                        HorizontalAlign="Center" />
                    <ItemTemplate>
                        <asp:Label
                            ID="Label_PriseConnaissance"
                            Text="X"
                            runat="server"
                            Visible='<%# Eval("PriseConnaissance") %>' />
                    </ItemTemplate>
                    <HeaderStyle
                        HorizontalAlign="Center" />
                </asp:TemplateField>
                <asp:TemplateField
                    HeaderText="Ajouté par"
                    InsertVisible="False"
                    SortExpression="AjoutePar">
                    <ItemStyle
                        Font-Size="0.8em" />
                    <ItemTemplate>
                        <asp:Label
                            ID="Label1"
                            runat="server"
                            Text='<%# LoginMod(Eval("AjoutePar").tostring) %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemStyle
                        Width="20px" />
                    <ItemTemplate>
                        <asp:ImageButton
                            ID="IBDetails"
                            runat="server"
                            PostBackUrl='<%# Eval("idIntervenant", "~/Intervenant.aspx?Mode=View&idIntervenant={0}") %>'
                            SkinID="Details" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:DropDownList
            ID="DropDownList2"
            runat="server"
            DataSourceID="SqlDataSourceEntreprise"
            DataTextField="IdEntreprise"
            DataValueField="idEntreprise"
            Visible="False">
        </asp:DropDownList>
    </asp:Panel>
    <asp:Panel
        ID="PanelIntervenant"
        runat="server"
        GroupingText=" "
        Visible="False"
        Width="100%">
        <div class="panelcontent">
            <uc1:Intervenant
                ID="UCIntervenant"
                runat="server" />
        </div>
        <br />
        <table style="width: 100%">
            <tr>
                <td align="left">
                    <asp:LinkButton
                        ID="LinkButtonRetour"
                        runat="server"
                        OnClick="LinkButtonRetour_Click"
                        CausesValidation="False">Retour</asp:LinkButton>
                </td>
                <td align="right">
                    <asp:LinkButton
                        ID="LinkButtonAjouter"
                        runat="server"
                        Visible="False">Ajouter</asp:LinkButton>
                    <asp:LinkButton
                        ID="LinkButtonMAJ"
                        runat="server"
                        Visible="False">Mettre à jour</asp:LinkButton></td>
            </tr>
        </table>
    </asp:Panel>
    <asp:SqlDataSource
        ID="SqlDataSourceIntervenantRestant"
        runat="server"
        ConnectionString="<%$ ConnectionStrings:PDP %>"
        SelectCommand="SELECT Intervenant.Nom + ISNULL(' ' + Intervenant.Prenom, '') AS NomPrenom, Intervenant.idIntervenant FROM PDP INNER JOIN Intervenant ON PDP.idEntreprise = Intervenant.idEntreprise WHERE (PDP.idPDP = @idPDP) AND (Intervenant.idIntervenant NOT IN (SELECT idIntervenant FROM IntervenantPDP WHERE (idPDP = @idPDP))) ORDER BY Intervenant.Nom + ISNULL(' ' + Intervenant.Prenom, '')">
        <SelectParameters>
            <asp:ControlParameter
                ControlID="ParamidPDP"
                DefaultValue="-1"
                Name="idPDP"
                PropertyName="Text" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource
        ID="SqlDataSourceIntervenantPDP"
        runat="server"
        ConnectionString="<%$ ConnectionStrings:PDP %>"
        DeleteCommand="DELETE FROM [IntervenantPDP] WHERE [idIntervenant] = @idIntervenant AND [idPDP] = @idPDP"
        InsertCommand="INSERT INTO [IntervenantPDP] ([idIntervenant], [idPDP], [PriseConnaissance], [AjoutePar]) VALUES (@idIntervenant, @idPDP, @PriseConnaissance, @AjoutePar)"
        SelectCommand="SELECT IntervenantPDP.idIntervenant, IntervenantPDP.idPDP, Intervenant.Nom + ISNULL(' ' + Intervenant.Prenom, '') AS NomPrenom, IntervenantPDP.PriseConnaissance, IntervenantPDP.AjoutePar, Intervenant.Nom, Intervenant.Prenom FROM IntervenantPDP INNER JOIN Intervenant ON IntervenantPDP.idIntervenant = Intervenant.idIntervenant WHERE (IntervenantPDP.idPDP = @idPDP) ORDER BY Intervenant.Nom, Intervenant.Prenom "
        UpdateCommand="UPDATE [IntervenantPDP] SET [PriseConnaissance] = @PriseConnaissance WHERE [idIntervenant] = @idIntervenant AND [idPDP] = @idPDP">
        <DeleteParameters>
            <asp:Parameter
                Name="idIntervenant"
                Type="Int32" />
            <asp:Parameter
                Name="idPDP"
                Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter
                Name="PriseConnaissance"
                Type="Boolean" />
            <asp:Parameter
                Name="idIntervenant"
                Type="Int32" />
            <asp:Parameter
                Name="idPDP"
                Type="Int32" />
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter
                ControlID="ParamidPDP"
                DefaultValue="-1"
                Name="idPDP"
                PropertyName="Text" />
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter
                Name="idIntervenant"
                Type="Int32" />
            <asp:Parameter
                Name="idPDP"
                Type="Int32" />
            <asp:Parameter
                Name="PriseConnaissance"
                Type="Boolean" />
            <asp:Parameter
                Name="AjoutePar"
                Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource
        ID="SqlDataSourceEntreprise"
        runat="server"
        ConnectionString="<%$ ConnectionStrings:PDP %>"
        SelectCommand="SELECT [idPDP], [idEntreprise] FROM [PDP] WHERE ([idPDP] = @idPDP)">
    </asp:SqlDataSource>

  4. #4
    Rédacteur
    Avatar de lutecefalco
    Profil pro
    zadzdzddzdzd
    Inscrit en
    Juillet 2005
    Messages
    5 052
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : zadzdzddzdzd

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 052
    Par défaut
    Tu violes une contrainte de clé étrangère.
    C'est un problème au niveau de ta base, pas de ton code

  5. #5
    Membre averti
    Étudiant
    Inscrit en
    Avril 2010
    Messages
    49
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2010
    Messages : 49
    Par défaut
    je suis parti voir dans ma base, mais dans la table concerné je n'est pas de clées etrangère.
    ma table "ntervenantPDP" a deux clés primaire "idintervenant" de la table intervenant et "IDPDP" de la table PDP
    je non comprend donc pas pourquoi sa ne fonctionne pas.

    quand je vai dans les details du message d'erreur, on m'indique

    Impossible d'inserer la valeur Null dans la colonne 'IdPDP', table suiviPDP.dbo.IntervenantPDP : cette colonne n'accepte pas la valeur NULL. Echec de insert. L'instruction a été arretée
    y a t'il une personne ayant une reponse a cela s'il vous plait ?

    cordialement

  6. #6
    Rédacteur
    Avatar de lutecefalco
    Profil pro
    zadzdzddzdzd
    Inscrit en
    Juillet 2005
    Messages
    5 052
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : zadzdzddzdzd

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 052
    Par défaut
    Le message est pourtant clair:
    impossible d'inserer la valeur Null dans la colonne 'IdPDP'

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

Discussions similaires

  1. probleme avec les exceptions SQL
    Par javalhoussain dans le forum ASP.NET
    Réponses: 8
    Dernier message: 26/04/2011, 17h55
  2. [C#] Exception SQL
    Par Procto dans le forum ASP.NET
    Réponses: 6
    Dernier message: 29/09/2005, 16h42
  3. [Exception]Probleme : Java.lang.Exception
    Par Nico66 dans le forum Général Java
    Réponses: 6
    Dernier message: 09/05/2005, 12h06
  4. [Struts]Sql Exceptions error
    Par Oby dans le forum Struts 1
    Réponses: 2
    Dernier message: 20/02/2005, 17h49
  5. [JDBC] SQL Exception lors d'une Query !
    Par Castagnems dans le forum JDBC
    Réponses: 5
    Dernier message: 30/04/2004, 12h00

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