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

Windows Forms Discussion :

bdd enregistrement null


Sujet :

Windows Forms

  1. #1
    Membre régulier
    Profil pro
    Enseignant
    Inscrit en
    Décembre 2006
    Messages
    324
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2006
    Messages : 324
    Points : 93
    Points
    93
    Par défaut bdd enregistrement null
    Bonjour,
    J'espère que je vais être claire

    1) J'ai créer une application qui gère des licences d'un club de sport.(Table joueurs) Base access
    2) Je renseigne un formulaire avec les licenciés et là le problème est que pour les champs vides j'ai trouvé qu'une solution(un peut nul, mais bon) je mets par défaut un 1 dans le champ. J'enregistre dans une table archive.
    Lorsque je veux visualiser le contenu de la table archive(par l'intermédiaire d'une autre form , la requette trouve un 1. Dans la table joueur le 1 correspond sur tous les champ à un ', et là ça plante pas parce que la requette trouve une valeur.
    3) C'est une usine à gaz, comment faire pour gérer les null dans la bdd????

    Code: Enregistrement des joueurs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     Me.txtref.Text = dtt.Rows(rownum).Item("IdJoueur")
            Me.txtnom.Text = dtt.Rows(rownum).Item("Nom")
            Me.txtprenom.Text = dtt.Rows(rownum).Item("Prenom")
            Me.txtlicence.Text = dtt.Rows(rownum).Item("Licence")
    Code: composition d'équipe
    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
     
     strIDEnt1 = Mid(Me.ComboEnt1.Text, 1, 5)
            strIDEnt2 = Mid(Me.ComboEnt2.Text, 1, 5)
            strIDSoi = Mid(Me.ComboSoi.Text, 1, 5)
            strIDMed = Mid(Me.ComboMed.Text, 1, 5)
            strIDAdj = Mid(Me.ComboAdj.Text, 1, 5)
            strIDRedac = Mid(Me.ComboRédact.Text, 1, 5)
            strIDFonct = Mid(Me.ComboFonction.Text, 1, 10)
            strIDDéleg = Mid(Me.Comboantidop.Text, 1, 5)
            strIDPréparateur = Mid(Me.ComboPreparateur.Text, 1, 5)
            '''''''''''''''''''''''''''''
            'combox arbitres
            strIDjuge = Mid(Me.Combjuge.Text, 1, 5)
     
            '''''''''''''''
            If strIDEnt1 = "" Then
                strIDEnt1 = "1"
            End If
     
            If strIDEnt2 = "" Then
                strIDEnt2 = "1"
            End If
     
            If strIDSoi = "" Then
                strIDSoi = "1"
            End If
    enregistrement des données dans la table archive

    Code de visualisation de l'archive
    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
     
      Dim MyConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Application.StartupPath & "\gestionjoueurs.mdb;Jet OLEDB:Database Password=admin;")
            Dim Mycommand As OleDbCommand = MyConnexion.CreateCommand()
            Dim intLong As Integer
            Dim strIdentifiant, strNumFeuille As String
     
            Mycommand.CommandText = "SELECT * from Archive_FeuilleMatch_SeniorRéserve where Id_feuille=" & CInt(strIdFeuille)
            MyConnexion.Open()
     
            Dim myReader As OleDbDataReader = Mycommand.ExecuteReader()
     
            myReader.Read()
     
            For j = 1 To 23
     
                Dim MyConnexion2 As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Application.StartupPath & "\gestionjoueurs.mdb;Jet OLEDB:Database Password=admi;")
                Dim Mycommand2 As OleDbCommand = MyConnexion2.CreateCommand()
     
                Mycommand2.CommandText = "SELECT IdJoueur,Nom,Prenom,Licence from T_Joueur where IdJoueur=" & CInt(myReader.GetValue(j))
                MyConnexion2.Open()
     
                Dim myReader2 As OleDbDataReader = Mycommand2.ExecuteReader()
                myReader2.Read()
                Select Case j
                    Case 1
     
     
                        TA1.Text = myReader2.GetValue(1)
                        TB1.Text = myReader2.GetValue(2)
                        TC1.Text = myReader2.GetValue(3)
                        If myReader2.GetValue(4) = True Then
                            LO1.Text = "O"
                            O1 = 1
                        End If
                        If myReader2.GetValue(4) = False Then
                            LO1.Text = ""
                            O1 = 0
                        End If
                        If myReader2.GetValue(5) = True Then
                            BJ1.Text = "BJ"
                            BJa1 = 1
                        End If
                        If myReader2.GetValue(5) = False Then
                            BJ1.Text = ""
                            BJa1 = 0
                        End If
                        If myReader2.GetValue(6) = True Then
                            B1.Text = "B"
                            Bl1 = 1
                        End If
                        If myReader2.GetValue(6) = False Then
                            B1.Text = ""
                            Bl1 = 0
                        End If
     
                    Case 2
     
     
                        TA2.Text = myReader2.GetValue(1)
                        TB2.Text = myReader2.GetValue(2)
                        TC2.Text = myReader2.GetValue(3)
                        If myReader2.GetValue(4) = True Then
                            LO2.Text = "O"
                            O2 = 1
                        End If
                        If myReader2.GetValue(4) = False Then
                            LO2.Text = ""
                            O2 = 0
                        End If
                        If myReader2.GetValue(5) = True Then
                            BJ2.Text = "BJ"
                            BJa2 = 1
                        End If
                        If myReader2.GetValue(5) = False Then
                            BJ2.Text = ""
                            BJa2 = 0
                        End If
                        If myReader2.GetValue(6) = True Then
                            B2.Text = "B"
                            Bl2 = 1
                        End If
                        If myReader2.GetValue(6) = False Then
                            B2.Text = ""
                            Bl2 = 0
                        End If
                    Case 3
    Bon est ce claire ???


    Merci par avance pour une piste ou un tuto

    @+
    Philippe

  2. #2
    Membre habitué Avatar de benito9253
    Homme Profil pro
    Inscrit en
    Août 2009
    Messages
    205
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 205
    Points : 196
    Points
    196
    Par défaut
    Bonjours,
    tu peux essayer de gérer les valeurs nulles en les testant avant de les utiliser avec IsDBNull()

    J'espère t'avoir un peu aidé.

  3. #3
    Membre régulier
    Profil pro
    Enseignant
    Inscrit en
    Décembre 2006
    Messages
    324
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2006
    Messages : 324
    Points : 93
    Points
    93
    Par défaut
    Bonjour.
    Voila un élément supplémentaire, ma requête SQL me donne le message suivant

    La conversion du type 'DBNull' en type 'Integer' n'est pas valide.
    Effectivement il y a des valeurs nul dans ma table pour une ligne donnée.

    Alors comment faire pour traiter ce pb

    merci
    @+
    philippe

  4. #4
    Membre habitué Avatar de benito9253
    Homme Profil pro
    Inscrit en
    Août 2009
    Messages
    205
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 205
    Points : 196
    Points
    196
    Par défaut
    Je n'ai pas tout compris de ce que tu voulais faire exactement mais il faut que tu teste chaque donnée que tu lis pour savoir si elle est nulle ou pas (comme je l'ai indiqué au dessus). Seulement après ca, si la valeur n'est pas nulle, tu peux utiliser la valeur...

    Je ne peux pas t'aidait beaucoup plus car je n'ai pas énormément d'expérience avec les bases de données

  5. #5
    Membre régulier
    Profil pro
    Enseignant
    Inscrit en
    Décembre 2006
    Messages
    324
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2006
    Messages : 324
    Points : 93
    Points
    93
    Par défaut
    bonjour et merci pour les infos

    Le problème est que je fais une requète avec une variable et j'utilise case, voir le 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
     
     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
     
            Dim strIdFeuille As String
            strIdFeuille = Mid(Me.ComboBox1.Text, 1, 5)
     
            Dim i, j As Integer
     
            Dim MyConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Application.StartupPath & "\gestionjoueurs.mdb;Jet OLEDB:Database Password=philguio;")
            Dim Mycommand As OleDbCommand = MyConnexion.CreateCommand()
            Dim intLong As Integer
            Dim strIdentifiant, strNumFeuille As String
     
            Mycommand.CommandText = "SELECT * from Archive_FeuilleMatch where Id_feuille=" & CInt(strIdFeuille)
            MyConnexion.Open()
     
            Dim myReader As OleDbDataReader = Mycommand.ExecuteReader()
     
            myReader.Read()
     
            For j = 1 To 23
     
                Dim MyConnexion2 As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Application.StartupPath & "\gestionjoueurs.mdb;Jet OLEDB:Database Password=philguio;")
                Dim Mycommand2 As OleDbCommand = MyConnexion2.CreateCommand()
     
     
                Mycommand2.CommandText = "SELECT IdJoueur,Nom,Prenom,Licence,Lorange,Lblanjaune,Lblanche from T_Joueur where IdJoueur=" & CInt(myReader.GetValue(j))
                MyConnexion2.Open()
     
                Dim myReader2 As OleDbDataReader = Mycommand2.ExecuteReader()
                myReader2.Read()
                Select Case j
                    Case 1
     
     
                        TA1.Text = myReader2.GetValue(1)
                        TB1.Text = myReader2.GetValue(2)
                        TC1.Text = myReader2.GetValue(3)
                        If myReader2.GetValue(4) = True Then
                            LO1.Text = "O"
                            O1 = 1
                        End If
                        If myReader2.GetValue(4) = False Then
                            LO1.Text = ""
                            O1 = 0
                        End If
                        If myReader2.GetValue(5) = True Then
                            BJ1.Text = "BJ"
                            BJa1 = 1
                        End If
                        If myReader2.GetValue(5) = False Then
                            BJ1.Text = ""
                            BJa1 = 0
                        End If
                        If myReader2.GetValue(6) = True Then
                            B1.Text = "B"
                            Bl1 = 1
                        End If
                        If myReader2.GetValue(6) = False Then
                            B1.Text = ""
                            Bl1 = 0
                        End If
     
                    Case 2
     
     
                        TA2.Text = myReader2.GetValue(1)
                        TB2.Text = myReader2.GetValue(2)
                        TC2.Text = myReader2.GetValue(3)
                        If myReader2.GetValue(4) = True Then
                            LO2.Text = "O"
                            O2 = 1
                        End If
                        If myReader2.GetValue(4) = False Then
                            LO2.Text = ""
                            O2 = 0
                        End If
                        If myReader2.GetValue(5) = True Then
                            BJ2.Text = "BJ"
                            BJa2 = 1
                        End If
                        If myReader2.GetValue(5) = False Then
                            BJ2.Text = ""
                            BJa2 = 0
                        End If
                        If myReader2.GetValue(6) = True Then
                            B2.Text = "B"
                            Bl2 = 1
                        End If
                        If myReader2.GetValue(6) = False Then
                            B2.Text = ""
                            Bl2 = 0
                        End If
                    Case 3
     
     
                        TA3.Text = myReader2.GetValue(1)
                        TB3.Text = myReader2.GetValue(2)
                        TC3.Text = myReader2.GetValue(3)
                        If myReader2.GetValue(4) = True Then
                            LO3.Text = "O"
                            O3 = 1
                        End If
                        If myReader2.GetValue(4) = False Then
                            LO3.Text = ""
                            O3 = 0
                        End If
                        If myReader2.GetValue(5) = True Then
                            BJ3.Text = "BJ"
                            BJa3 = 1
                        End If
                        If myReader2.GetValue(5) = False Then
                            BJ3.Text = ""
                            BJa3 = 0
                        End If
                        If myReader2.GetValue(6) = True Then
                            B3.Text = "B"
                            Bl3 = 1
                        End If
                        If myReader2.GetValue(6) = False Then
                            B3.Text = ""
                            Bl3 = 0
     
                        End If
                    Case 4
     
                        TA4.Text = myReader2.GetValue(1)
                        TB4.Text = myReader2.GetValue(2)
                        TC4.Text = myReader2.GetValue(3)
                        If myReader2.GetValue(4) = True Then
                            LO4.Text = "O"
                            O4 = 1
                        End If
                        If myReader2.GetValue(4) = False Then
                            LO4.Text = ""
                            O4 = 0
                        End If
                        If myReader2.GetValue(5) = True Then
                            BJ4.Text = "BJ"
                            BJa4 = 1
                        End If
                        If myReader2.GetValue(5) = False Then
                            BJ4.Text = ""
                            BJa4 = 0
                        End If
                        If myReader2.GetValue(6) = True Then
                            B4.Text = "B"
                            Bl4 = 1
                        End If
                        If myReader2.GetValue(6) = False Then
                            B4.Text = ""
                            Bl4 = 0
                        End If
                    Case 5
     
                        TA5.Text = myReader2.GetValue(1)
                        TB5.Text = myReader2.GetValue(2)
                        TC5.Text = myReader2.GetValue(3)
                        If myReader2.GetValue(4) = True Then
                            LO5.Text = "O"
                            O5 = 1
                        End If
                        If myReader2.GetValue(4) = False Then
                            LO5.Text = ""
                            O5 = 0
                        End If
                        If myReader2.GetValue(5) = True Then
                            BJ5.Text = "BJ"
                            BJa5 = 1
                        End If
                        If myReader2.GetValue(5) = False Then
                            BJ5.Text = ""
                            BJa5 = 0
                        End If
                        If myReader2.GetValue(6) = True Then
                            B5.Text = "B"
                            Bl5 = 1
                        End If
                        If myReader2.GetValue(6) = False Then
                            B5.Text = ""
                            Bl5 = 0
                        End If
                    Case 6
     
                        TA6.Text = myReader2.GetValue(1)
                        TB6.Text = myReader2.GetValue(2)
                        TC6.Text = myReader2.GetValue(3)
                        If myReader2.GetValue(4) = True Then
                            LO6.Text = "O"
                            O6 = 1
                        End If
                        If myReader2.GetValue(4) = False Then
                            LO6.Text = ""
                            O6 = 0
                        End If
                        If myReader2.GetValue(5) = True Then
                            BJ6.Text = "BJ"
                            BJa6 = 1
                        End If
                        If myReader2.GetValue(5) = False Then
                            BJ6.Text = ""
                            BJa6 = 0
                        End If
                        If myReader2.GetValue(6) = True Then
                            B6.Text = "B"
                            Bl6 = 1
                        End If
                        If myReader2.GetValue(6) = False Then
                            B6.Text = ""
                            Bl6 = 0
                        End If
                    Case 7
     
                        TA7.Text = myReader2.GetValue(1)
                        TB7.Text = myReader2.GetValue(2)
                        TC7.Text = myReader2.GetValue(3)
                        If myReader2.GetValue(4) = True Then
                            LO7.Text = "O"
                            O7 = 1
                        End If
                        If myReader2.GetValue(4) = False Then
                            LO7.Text = ""
                            O7 = 0
                        End If
                        If myReader2.GetValue(5) = True Then
                            BJ7.Text = "BJ"
                            BJa7 = 1
                        End If
                        If myReader2.GetValue(5) = False Then
                            BJ7.Text = ""
                            BJa7 = 0
                        End If
                        If myReader2.GetValue(6) = True Then
                            B7.Text = "B"
                            Bl7 = 1
                        End If
                        If myReader2.GetValue(6) = False Then
                            B7.Text = ""
                            Bl7 = 0
                        End If
    et ça de nombreuse fois, donc je ne sais pas quoi faire

    merci
    @+
    Philippe

  6. #6
    Membre régulier
    Profil pro
    Enseignant
    Inscrit en
    Décembre 2006
    Messages
    324
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2006
    Messages : 324
    Points : 93
    Points
    93
    Par défaut
    Bon j'ai trouvé une solution ???? il y peut être mieux

    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
     
     Try
     
                TA23.Text = myReader221.GetValue(1)
                TB23.Text = myReader221.GetValue(2)
                TC23.Text = myReader221.GetValue(3)
                If myReader221.GetValue(4) = True Then
                    LO23.Text = "O"
                    O23 = 1
                End If
                If myReader221.GetValue(4) = False Then
                    LO23.Text = ""
                    O23 = 0
                End If
                If myReader221.GetValue(5) = True Then
                    BJ23.Text = "BJ"
                    BJa23 = 1
                End If
                If myReader221.GetValue(5) = False Then
                    BJ23.Text = ""
                    BJa23 = 0
                End If
                If myReader221.GetValue(6) = True Then
                    B23.Text = "B"
                    Bl23 = 1
                End If
                If myReader221.GetValue(6) = False Then
                    B23.Text = ""
                    Bl23 = 0
                End If
                If myReader221.GetValue(1) = "'" Then
                    TA23.Text = ""
                End If
     
                If myReader221.GetValue(3) = "'" Then
                    TC23.Text = ""
                End If
            Catch
                GoTo line8
            End Try
    line8:
    merci pour les infos
    @+
    Philippe

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

Discussions similaires

  1. [C# ComboBox-Bdd]rendre null une valeur dans une base
    Par arthenius dans le forum Windows Forms
    Réponses: 8
    Dernier message: 25/03/2009, 16h11
  2. [Debutant] Selection enregistrement Null
    Par brak__ dans le forum Access
    Réponses: 30
    Dernier message: 04/01/2007, 16h36
  3. [Debutant] Requete SELECT enregistrement NULL
    Par brak__ dans le forum Requêtes et SQL.
    Réponses: 16
    Dernier message: 22/12/2006, 16h03
  4. Creation d'enregistrement null
    Par el_quincho dans le forum Access
    Réponses: 1
    Dernier message: 28/06/2006, 11h37
  5. [BDD] Enregistrer le résultat d'une requête
    Par Mowgly dans le forum C++Builder
    Réponses: 5
    Dernier message: 19/06/2002, 15h26

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