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 :

message d'erreur de référence d'objet


Sujet :

VB.NET

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2012
    Messages : 48
    Points : 45
    Points
    45
    Par défaut message d'erreur de référence d'objet
    salut tout le monde.
    en exécutant mon programme, le message d'erreur suivant s'affiche:
    La référence d'objet n'est pas définie à une instance d'un objet
    j'ai trouvé ma faute SVP aidez moi.voila le code que j'utilise:
    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
     
    Private Sub Button2_Click(ByVal sender AS System.Object, ByVal e AS System.EventArgs) Handles Button2.Click
            IF NOT (TextBox1.Text = "") AND NOT (TextBox2.Text = "") AND NOT (TextBox4.Text = "") Then
     
     
                Dim strsql AS String = "Select * from responsable"
                Dim strConnexion AS String = "Persist Security Info=true;Integrated Security=SSPI;database=parc municipal;server=USER-PC\AHMED"
                Dim x AS Exception
     
                    Dim oConnection AS New SqlConnection(strConnexion)
                    oConnection.Open()
                    Dim ObjetDA AS New SqlDataAdapter(strsql, oConnection)
                    ObjetDA.Fill(Parc_municipalDataSet1, "responsable")
                    ObjetDA.InsertCommand = New SqlCommand("INSERT INTO responsable(num_matricule,nom_prenom, titre) Values(@num_matricule,@nom_prenom,@titre)", oConnection)
                    ObjetDA.InsertCommand.Parameters.ADD("@num_matricule", SqlDbType.Int, 15, "num_matricule")
                    ObjetDA.InsertCommand.Parameters.ADD("@nom_prenom", SqlDbType.NVarChar, 15, "nom_prenom")
                    ObjetDA.InsertCommand.Parameters.ADD("@titre", SqlDbType.NVarChar, 15, "titre")
     
     
     
                    Dim DR AS DataRow
                    DR = Parc_municipalDataSet1.TABLES("responsable").NewRow
                    DR("num_matricule") = TextBox1.Text
                    DR("titre") = TextBox4.Text
                    DR("nom_prenom") = TextBox2.Text
                    Parc_municipalDataSet1.TABLES("responsable").Rows.ADD(DR)
                    ObjetDA.UPDATE(Parc_municipalDataSet1, "responsable")
                    Parc_municipalDataSet1.Clear()
                    ObjetDA.Fill(Parc_municipalDataSet1, "responsable")
     
                    Parc_municipalDataSet1.concerner_r.Constraints.ADD("FK_concerner_r_responsable", Parc_municipalDataSet1.responsable.COLUMNS("num_matricule"), Parc_municipalDataSet1.concerner_r.COLUMNS("num_matricule"))
                    Parc_municipalDataSet1.concerner_r.Constraints.ADD("FK_concerner_r_categorie", Parc_municipalDataSet1.categorie.COLUMNS("nom_cat"), Parc_municipalDataSet1.concerner_r.COLUMNS("nom_cat"))
     
     
     
                    Dim DR1 AS DataRow
                    DR1 = Parc_municipalDataSet1.TABLES("concerner_r").NewRow
                    DR1("num_matricule") = TextBox1.Text
                    DR1("nom_cat") = ComboBox1.SelectedItem.ToString
                    Parc_municipalDataSet1.TABLES("concerner_r").Rows.ADD(DR1)
                    ObjetDA.UPDATE(Parc_municipalDataSet1, "concerner_r")
                    Parc_municipalDataSet1.Clear()
                    ObjetDA.Fill(Parc_municipalDataSet1, "concerner_r")
    merciiii bein

  2. #2
    Membre émérite Avatar de meziantou
    Homme Profil pro
    Ingénieur R&D
    Inscrit en
    Avril 2010
    Messages
    1 223
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Canada

    Informations professionnelles :
    Activité : Ingénieur R&D
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 1 223
    Points : 2 439
    Points
    2 439
    Par défaut
    L'erreur se produit sur quelle ligne ?

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2012
    Messages : 48
    Points : 45
    Points
    45
    Par défaut
    voila le code avec l'exception:
    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
     
     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            If Not (TextBox1.Text = "") And Not (TextBox2.Text = "") And Not (TextBox4.Text = "") Then
                MsgBox(ComboBox1.SelectedValue.ToString)
     
                Dim strsql As String = "Select * from responsable"
                Dim strConnexion As String = "Persist Security Info=true;Integrated Security=SSPI;database=parc municipal;server=USER-PC\AHMED"
     
     
                Dim x As Exception
                Try
                    Dim oConnection As New SqlConnection(strConnexion)
                    oConnection.Open()
                    Dim ObjetDA As New SqlDataAdapter(strsql, oConnection)
                    ObjetDA.Fill(Parc_municipalDataSet1, "responsable")
                    ObjetDA.InsertCommand = New SqlCommand("INSERT INTO responsable(num_matricule,nom_prenom, titre) Values(@num_matricule,@nom_prenom,@titre)", oConnection)
                    ObjetDA.InsertCommand.Parameters.Add("@num_matricule", SqlDbType.Int, 15, "num_matricule")
                    ObjetDA.InsertCommand.Parameters.Add("@nom_prenom", SqlDbType.NVarChar, 15, "nom_prenom")
                    ObjetDA.InsertCommand.Parameters.Add("@titre", SqlDbType.NVarChar, 15, "titre")
     
     
     
                    Dim DR As DataRow
                    DR = Parc_municipalDataSet1.Tables("responsable").NewRow
                    DR("num_matricule") = TextBox1.Text
                    DR("titre") = TextBox4.Text
                    DR("nom_prenom") = TextBox2.Text
                    Parc_municipalDataSet1.Tables("responsable").Rows.Add(DR)
                    ObjetDA.Update(Parc_municipalDataSet1, "responsable")
                    Parc_municipalDataSet1.Clear()
                    ObjetDA.Fill(Parc_municipalDataSet1, "responsable")
     
                    Dim DR1 As DataRow
                    DR1 = Parc_municipalDataSet1.Tables("concerner_r").NewRow
                    DR1("num_matricule") = TextBox1.Text
     
                    DR1("nom_cat") = ComboBox1.SelectedValue.ToString
     
     
     
                    Parc_municipalDataSet1.Tables("concerner_r").Rows.Add(DR1)
                    ObjetDA.Update(Parc_municipalDataSet1, "concerner_r")
                    Parc_municipalDataSet1.Clear()
                    ObjetDA.Fill(Parc_municipalDataSet1, "concerner_r")
     
     
     
                    oConnection.Close()
                    MsgBox("succés d'ajout ", MsgBoxStyle.OkOnly, "ajout responsable")
                    Me.Hide()
                Catch x
                    MsgBox("L'erreur suivante a été rencontrée :" & x.Message)
                End Try


    en fait l'erreur ne se produit qu'à la ligne
    Catch x

  4. #4
    Invité
    Invité(e)
    Par défaut
    Retire ta ligne

    Et remplace ton

    Par

  5. #5
    Membre émérite Avatar de mactwist69
    Homme Profil pro
    Développement VB.NET
    Inscrit en
    Janvier 2007
    Messages
    1 707
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : Développement VB.NET
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 707
    Points : 2 528
    Points
    2 528
    Par défaut
    Bonjour,

    Une des méthodes de débogage est le "pas-a-pas".

    Tu clique-gauche sur la partie la plus à gauche de la première ligne de ton code, ça fait apparaître un point rouge: un point d’arrêt.

    Lorsque ton code arrive sur ce point d'arrêt, il s’arrête et ta ligne devient jaune.
    A ce moment tu appuis sur F10 pour qu'il passe à la ligne suivante. Tu presses F10 jusqu’à ce qu'a un moment, le code ne va pas à la ligne suivante mais se rends directement dans le Catch.

    Tu auras trouvé la ligne qui bug.

Discussions similaires

  1. Réponses: 5
    Dernier message: 25/10/2011, 10h31
  2. Réponses: 16
    Dernier message: 22/02/2010, 17h18
  3. Réponses: 7
    Dernier message: 31/12/2009, 09h10
  4. Réponses: 20
    Dernier message: 13/08/2007, 16h11
  5. Réponses: 8
    Dernier message: 04/06/2007, 16h20

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