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 :

erreur NullReferenceException


Sujet :

VB.NET

  1. #1
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Mars 2010
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2010
    Messages : 28
    Points : 15
    Points
    15
    Par défaut erreur NullReferenceException
    Bonjour,

    j'ai un problème sur une application en objet qui permet de modifier les informations d'un propriétaire ou d'en créer un.

    Mais lors de l'enregistrement en mode création j'ai une erreur NullReferenceException sur l'appel de ma fonction AjouterProprietaire()

    Quant à la modification rien ne s'effectue.

    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
    Private Sub btSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSave.Click
     
            If o_Proprietaire Is Nothing Then
                'demander au SI d'ajouter une catégorie
                o_Proprietaire = o_si.AjouterProprietaire(txtNom.Text, txtPrenom.Text, txtAdr.Text, txtMail.Text, txtTel.Text, txtMDP.Text, txtRemark.Text)
                If o_Proprietaire IsNot Nothing Then
                    Me.Visible = False
                End If
            End If
            'demander au SI de modifier
            If o_si.ModifierProprietaire(o_Proprietaire, txtNom.Text, txtPrenom.Text, txtAdr.Text, _
                                          txtTel.Text, txtMail.Text, txtMDP.Text, txtRemark.Text) Then
                Me.Visible = False
            End If
     
        End Sub
     
     
     
      Public Function AjouterProprietaire(ByVal TheNom As String, ByVal ThePrenom As String, ByVal TheAdr As String, _
                                            ByVal TheMail As String, ByVal TheTel As String, ByVal TheMDP As String, ByVal TheRemark As String) As Proprietaire
            Dim TRANS As OleDb.OleDbTransaction = Nothing
            Dim NouveauProprio As Proprietaire
            Dim TheId As String = GenerateProId()
            ' 
     
            Try
                Dim o_cnx As New OleDb.OleDbConnection
                o_cnx.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Elissa\Desktop\Location\Location.mdb"
                o_SQLInsertPro = New OleDb.OleDbCommand()
                o_SQLInsertPro.Connection = o_cnx
                o_SQLInsertPro.Connection.Open()
                '--- Début de transaction
                TRANS = o_SQLInsertPro.Connection.BeginTransaction
                '--- La commande doit travailller sous la transaction
                o_SQLInsertPro.Transaction = TRANS
                '--- Donner les valeurs des paramètres
                'INSERT INTO PROPRIETAIRE
                '(PRO_NOM, PRO_PRENOM, PRO_COORD, PRO_TEL, PRO_MAIL, PRO_MDP, PRO_REMARK, PRO_ID)
                'VALUES        (?, ?, ?, ?, ?, ?, ?, ?)
                o_SQLInsertPro.Parameters.Item(0).Value = TheNom
                o_SQLInsertPro.Parameters.Item(1).Value = ThePrenom
                o_SQLInsertPro.Parameters.Item(2).Value = TheAdr
                o_SQLInsertPro.Parameters.Item(3).Value = TheMail
                o_SQLInsertPro.Parameters.Item(4).Value = TheMDP
                o_SQLInsertPro.Parameters.Item(4).Value = TheRemark
                o_SQLInsertPro.Parameters.Item(4).Value = TheId
     
                Dim Nb As Integer = o_SQLInsertPro.ExecuteNonQuery
                If Nb = 1 Then
                    TRANS.Commit()
                    '--- Ajout dans le monde objet
                    NouveauProprio = New Proprietaire(TheId, TheNom, ThePrenom, TheAdr, TheTel, TheMail, TheMDP, TheRemark)
                    o_ListProprietaire.Ajouter(NouveauProprio)
                    Return NouveauProprio
                Else : TRANS.Rollback()
                End If
            Catch ex As Exception
                If TRANS IsNot Nothing Then
                    TRANS.Rollback()
                End If
            End Try
            Return Nothing
        End Function
     
        Public Function ModifierProprietaire(ByVal TheProprietaire As Proprietaire, _
                                         ByVal TheNewNom As String, _
                                         ByVal TheNewPrenom As String, _
                                         ByVal TheNewAdr As String, _
                                         ByVal TheNewTel As String, _
                                         ByVal TheNewMail As String, _
                                         ByVal TheNewMDP As String, _
                                         ByVal TheNewRemark As String) As Boolean
     
            Dim TRANS As OleDb.OleDbTransaction = Nothing
            Dim Aretourner As Boolean = Nothing
     
            Try
                Dim o_cnx As New OleDb.OleDbConnection
     
                o_cnx.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Elissa\Desktop\Location\Location.mdb"
                o_SQLUpdatePro = New OleDb.OleDbCommand()
                o_SQLUpdatePro.Connection = o_cnx
                o_SQLUpdatePro.Connection.Open()
                '--- Début de la transaction
                TRANS = o_SQLUpdatePro.Connection.BeginTransaction
                '--- La commande doit travailler sous la transaction
                o_SQLUpdatePro.Transaction = TRANS
                '--- Donner les valeurs des paramètres
                'UPDATE(Proprietaire)
                'SET PRO_NOM = ?, PRO_PRENOM=?, PRO_COORD=?, PRO_TEL=?, PRO_MAIL=?, PRO_MDP=?, PRO_REMARK=?
                'WHERE (PRO_ID = ?)
                o_SQLUpdatePro.Parameters.Item(0).Value = TheNewNom
                o_SQLUpdatePro.Parameters.Item(1).Value = TheNewPrenom
                o_SQLUpdatePro.Parameters.Item(2).Value = TheNewAdr
                o_SQLUpdatePro.Parameters.Item(3).Value = TheNewTel
                o_SQLUpdatePro.Parameters.Item(4).Value = TheNewMail
                o_SQLUpdatePro.Parameters.Item(5).Value = TheNewMDP
                o_SQLUpdatePro.Parameters.Item(6).Value = TheNewRemark
                o_SQLUpdatePro.Parameters.Item(7).Value = TheProprietaire.Id
     
                Dim nb As Integer = o_SQLUpdatePro.ExecuteNonQuery
                If nb = 1 Then
                    TRANS.Commit()
                    'Modif dans le monde objet
                    TheProprietaire.Nom = TheNewNom
                    TheProprietaire.Prenom = TheNewPrenom
                    TheProprietaire.Coord = TheNewAdr
                    TheProprietaire.Mail = TheNewMail
                    TheProprietaire.Telephone = TheNewTel
                    TheProprietaire.MDP = TheNewMDP
                    TheProprietaire.Remarques = TheNewRemark
     
                    Aretourner = True
                Else
                    TRANS.Rollback()
                End If
            Catch ex As Exception
                If TRANS IsNot Nothing Then
                    TRANS.Rollback()
                End If
            End Try
            Return Aretourner
        End Function

    merci par avance pour votre aide, je dois finaliser cette application jeudi matin

  2. #2
    Membre expérimenté Avatar de hunteshiva
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Février 2010
    Messages
    1 069
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2010
    Messages : 1 069
    Points : 1 455
    Points
    1 455
    Par défaut
    oui et .....
    tu pourrais préciser l'endroit ou se situe l'erreur *stp*

    regarde la ligne ou tu a ton erreur,
    il devrais t'indiquer une variable,
    tu fait click droit sur cette dernière puis "atteindre la définition"
    tu va arriver directement a la ligne ou tu l'a déclaré

    si c'est une variable simple de type integer ou string, tu met

  3. #3
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Mars 2010
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2010
    Messages : 28
    Points : 15
    Points
    15
    Par défaut
    c'est à l'appel de la fonction l'erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    o_Proprietaire = o_si.AjouterProprietaire(txtNom.Text, txtPrenom.Text, txtAdr.Text, txtMail.Text, txtTel.Text, txtMDP.Text, txtRemark.Text)
    Pourtant tout mes champs sont remplis.

    En mettant un point d'arrêt je ne rentre pas dans la fonction mais l'erreur peut y être quant même ?

  4. #4
    Membre expérimenté Avatar de hunteshiva
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Février 2010
    Messages
    1 069
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2010
    Messages : 1 069
    Points : 1 455
    Points
    1 455
    Par défaut
    donne moi un screen don ton erreur pour voir
    (avec la barre en bas qui montre la ligne)

  5. #5
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Mars 2010
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2010
    Messages : 28
    Points : 15
    Points
    15
    Par défaut
    Mais il ne m'affiche pas de ligne d'erreur en bas.

  6. #6
    Membre expérimenté Avatar de hunteshiva
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Février 2010
    Messages
    1 069
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2010
    Messages : 1 069
    Points : 1 455
    Points
    1 455
    Par défaut
    erreur NullReferenceException
    tu l'a pas trouvé tout seul celle la pourtant ....

  7. #7
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Mars 2010
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2010
    Messages : 28
    Points : 15
    Points
    15
    Par défaut
    Voila mon imprime écran
    Fichiers attachés Fichiers attachés

  8. #8
    Membre expérimenté Avatar de hunteshiva
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Février 2010
    Messages
    1 069
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2010
    Messages : 1 069
    Points : 1 455
    Points
    1 455
    Par défaut
    okay ... et dans afficher les détails tu a quoi alors ?

    PS: j'ais remis ton image mais de manière a ce qu'on puisse la lire directement


  9. #9
    Membre du Club
    Homme Profil pro
    Technicien Qualité Logiciel
    Inscrit en
    Janvier 2010
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Technicien Qualité Logiciel
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2010
    Messages : 44
    Points : 45
    Points
    45
    Par défaut
    Salut,

    Comment déclares-tu o_Proprietaire??

    Car comme tu le vois dans l'explication de ton erreur, il te suggère de créer une nouvelle instance pour cet objet.

    Essayer d'ajouter dans la déclaration de variable : Dim o_Proprietaire as NEW ...

    Pour la suite de ton code il ne doit pas détecté si o_Proprietaire n'est pas nothing car tu le vérifie dans la même condition que si o_Proprietaire est nothing

  10. #10
    Modérateur
    Avatar de sevyc64
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    10 193
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 10 193
    Points : 28 077
    Points
    28 077
    Par défaut
    Dans le cas présent c'est plutôt o_SI qui n'est pas défini et qui génère l'erreur
    --- Sevyc64 ---

    Parce que le partage est notre force, la connaissance sera notre victoire

  11. #11
    Membre du Club
    Homme Profil pro
    Technicien Qualité Logiciel
    Inscrit en
    Janvier 2010
    Messages
    44
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Technicien Qualité Logiciel
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2010
    Messages : 44
    Points : 45
    Points
    45
    Par défaut
    Oh oui milles excuses

Discussions similaires

  1. Réponses: 12
    Dernier message: 14/01/2019, 01h12
  2. [Débutant] Lecture tableau Excel erreur NullReferenceException
    Par teo971 dans le forum VB.NET
    Réponses: 13
    Dernier message: 28/02/2014, 18h48
  3. Erreur System.NullReferenceException avec MySQL
    Par CleeM dans le forum Windows Forms
    Réponses: 4
    Dernier message: 26/02/2008, 17h17
  4. Réponses: 2
    Dernier message: 29/01/2008, 12h04

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