1 pièce(s) jointe(s)
La référence d'objet n'est pas définie à une instance d'un objet.
Bonjour,
J'ai un problème avec la modification et la suppression dans une application qui fait la gestion du personnel, l'erreur "La référence d'objet n'est pas définie à une instance d'un objet." s'affiche après que la fonction de la recherche s’exécute, apres que je clique sur modifier ou supprimer, voila le code de ma classe :
Code:
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
| Imports System.Data.OleDb
Imports System.Windows.Forms
Public Class informatique_connection
Public mycon As OleDbConnection
Public strcon As String
Public rdr As OleDbDataReader
Public myreq As String
Public cmd As OleDbCommand
Public Sub connecting_in_informatique()
strcon = "provider=Microsoft.ACE.OLEDB.12.0; Data source=C:\Users\user\Documents\bd.accdb"
mycon = New OleDbConnection(strcon)
mycon.Open()
End Sub
Public Sub disconnecting_in_informatique()
rdr.Close()
mycon.Close()
End Sub
Public Function RechercheSelonMatricule(ByVal idmatricule As Integer) As OleDbDataReader
Dim sql As String = String.Empty
Dim command As New OleDbCommand(sql, mycon)
command.CommandText = " SELECT * FROM Perso WHere Matricule = [?];"
command.Parameters.Add("?", OleDbType.Integer).Value = idmatricule
Return command.ExecuteReader()
End Function
End Class |
voila le code de la modification :
Code:
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
| Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
db_informatique.myreq = "UPDATE Perso SET Matricule = '" & a1.Text.Trim & "' , Nom = '" & a2.Text.Trim & "', Prenom ='" & a3.Text.Trim & "' , CIN = '" & a4.Text.Trim & "', Date de naissance = '" & a5.Text.Trim & "' , Adresse = '" & a6.Text.Trim & "', Tél = '" & a7.Text.Trim & "', E-mail = '" & a8.Text.Trim & "', Situation familiale = '" & a9.Text.Trim & "', Date de recrutement = '" & a10.Text.Trim & "', Date previsible de retraitet = '" & a11.Text.Trim & "', Echelle = '" & a12.Text.Trim & "', Formations de base = '" & a13.Text.Trim & "', droit de congé = '" & a14.Text.Trim & "', jours restants du congé = '" & a15.Text.Trim & "' WHERE Matricule = '" & a1.Text & "' "
db_informatique.connecting_in_informatique()
db_informatique.disconnecting_in_informatique()
MessageBox.Show("Modification effectuée!")
Me.Mettre_au_blanc()
End Sub
Public Sub Mettre_au_blanc()
Me.a1.Text = " "
Me.a2.Text = " "
Me.a3.Text = " "
Me.a4.Text = " "
Me.a5.Text = " "
Me.a6.Text = " "
Me.a7.Text = " "
Me.a8.Text = " "
Me.a9.Text = " "
Me.a10.Text = " "
Me.a11.Text = " "
Me.a12.Text = " "
Me.a13.Text = " "
Me.a14.Text = " "
Me.a15.Text = " "
End Sub |
et voila le code de la suppression :
Code:
1 2 3 4 5
| Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
db_informatique.myreq = "DELETE * FROM Perso WHere Matricule = '" & a1.Text & "' "
db_informatique.connecting_in_informatique()
db_informatique.disconnecting_in_informatique()
End Sub |
quelqu'un pourra m'aider?? :?
Merci d'avance...