Erreur au niveau de la suppression et de la modification
kright
Messages postés1Date d'inscriptionvendredi 9 novembre 2007StatutMembreDernière intervention26 août 2010
-
26 août 2010 à 11:28
Mayzz
Messages postés2813Date d'inscriptionmardi 15 avril 2003StatutMembreDernière intervention 2 juin 2020
-
27 août 2010 à 01:07
Bonjour à tous je suis débutant en vb.net et voici que je suis bloqué sur une erreur au niveau de la modification et de la suppression de mes données. J'utilise une connection oledb pour lier une base de donnée access à vb 2008
voici mon code
Private Sub BtnModifier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnModifier.Click
If Me.Txtdatevol.Text "" Or Me.TxtHeuredep.Text "" Or Me.Txtheurearriv.Text = "" Or Me.Txtnumpilote.Text = "" _
Or Me.Txtnumavion.Text "" Or Me.Txtnumtrajet.Text "" Then
MessageBox.Show("Vous devez remplir tous les champs !", "Erreur...", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Cmbpilote.Focus()
Exit Sub
End If
Txtdatevol.Format = DateTimePickerFormat.Short
'
'strSQL = "UPDATE personnes SET nom='" & txtNom.Text & "', prenom='" & txtPrenom.Text & "', tel='" & txtTel.Text & "', email='" & txtEmail.Text & "' WHERE id=" & lblId.Text
'
Ocommande.CommandText "UPDATE EFFECTUER set Heuredep'" & TxtHeuredep.Text & "', Heurearriv ='" & Txtheurearriv.Text & "' WHERE Numpilote = '" & Txtnumpilote.Text & "' AND Numavion = '" _
& Txtnumavion.Text & "' AND Numtrajet '" & Txtnumtrajet.Text & "' AND Datevol '" & Txtdatevol.Text & "'"
Ocommande.Connection = Oconnexion
Try
'Oconnexion.Open()
Ocommande.ExecuteNonQuery()
MsgBox(" Modification réalisée pour EFFECTUER")
Catch ex As OleDb.OleDbException
MsgBox(ex.ToString)
Exit Sub
End Try
Ocommande.CommandText = "SELECT Numpilote, Numavion, Numtrajet, Datevol, Heuredep, Heurearriv FROM EFFECTUER"
Odreader = Ocommande.ExecuteReader 'récuperation du resultat de l'exécution de la requête cmd
Dim i As Integer = 0
Do While Odreader.Read 'tanque on peut lire un enregistrement
'DataGridView1.Rows.Add() 'ajout de ligne
DataGridView1.Rows(i).Cells(0).Value = Odreader(0) 'affichage de colonne
DataGridView1.Rows(i).Cells(1).Value = Odreader(1)
DataGridView1.Rows(i).Cells(2).Value = Odreader(2)
DataGridView1.Rows(i).Cells(3).Value = Odreader(3)
DataGridView1.Rows(i).Cells(4).Value = Odreader(4)
DataGridView1.Rows(i).Cells(5).Value = Odreader(5)
i = i + 1
Loop
Oconnexion.Close()
End Sub
If Me.Txtdatevol.Text "" Or Me.TxtHeuredep.Text "" Or Me.Txtheurearriv.Text = "" Or Me.Txtnumpilote.Text = "" _
Or Me.Txtnumavion.Text "" Or Me.Txtnumtrajet.Text "" Then
MessageBox.Show("Vous devez remplir tous les champs !", "Erreur...", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Cmbpilote.Focus()
Exit Sub
End If
Txtdatevol.Format = DateTimePickerFormat.Short
'
'strSQL = "UPDATE personnes SET nom='" & txtNom.Text & "', prenom='" & txtPrenom.Text & "', tel='" & txtTel.Text & "', email='" & txtEmail.Text & "' WHERE id=" & lblId.Text
'
'Ocommande.CommandText "update EFFECTUER set heuredep'" & TxtHeuredep.Text & "', heurearriv ='" & Txtheurearriv.Text & "' WHERE Numpilote = '" & Txtnumpilote.Text & "' AND Numavion = '" & Txtnumavion.Text & "' AND Numavion = '" & Txtnumavion.Text & "'AND Datevol = '" & Txtdatevol.Text & "'"
Ocommande.CommandText "DELETE FROM EFFECTUER WHERE Numpilote '" & Txtnumpilote.Text & "' AND Numavion = '" & Txtnumavion.Text & "' AND Numtrajet = '" & Txtnumtrajet.Text & "'AND Datevol = '" & Txtdatevol.Text & "'"
Ocommande.Connection = Oconnexion
Try
'Oconnexion.Open()
Ocommande.ExecuteNonQuery()
MsgBox(" Suppression réalisée pour EFFECTUER")
Catch ex As OleDb.OleDbException
MsgBox(ex.ToString)
Exit Sub
End Try
Ocommande.CommandText = "SELECT Numpilote, Numavion, Numtrajet, Datevol, Heuredep, Heurearriv FROM EFFECTUER"
Odreader = Ocommande.ExecuteReader 'récuperation du resultat de l'exécution de la requête cmd
Dim i As Integer = 0
Do While Odreader.Read 'tanque on peut lire un enregistrement
'DataGridView1.Rows.Add() 'ajout de ligne
DataGridView1.Rows(i).Cells(0).Value = Odreader(0) 'affichage de colonne
DataGridView1.Rows(i).Cells(1).Value = Odreader(1)
DataGridView1.Rows(i).Cells(2).Value = Odreader(2)
DataGridView1.Rows(i).Cells(3).Value = Odreader(3)
DataGridView1.Rows(i).Cells(4).Value = Odreader(4)
DataGridView1.Rows(i).Cells(5).Value = Odreader(5)
i = i + 1
Loop
Oconnexion.Close()
End Sub
et voici l'erreur qu'il affiche
Data type mismatch in criteria expression.
à System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) à System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) à System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) à System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) à System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) à System.Data.OleDb.OleDbCommand.ExecuteNonQuery() à Voyage.FrmVol.BtnModifier_Click(Object sender, EventArgs e) dans C:\Users\Dymex\Documents\Visual Studio 2008\Projects\Voyage\Voyage\FrmVol.vb:ligne 257 à System.Windows.Forms.Control.OnClick(EventArgs e) à System.Windows.Forms.Button.OnClick(EventArgs e) à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) à System.Windows.Forms.Control.WndProc(Message& m) à System.Windows.Forms.ButtonBase.WndProc(Message& m) à System.Windows.Forms.Button.WndProc(Message& m) à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) à System.Windows.Forms.Application.Run(ApplicationContext context) à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) à Voyage.My.MyApplication.Main(String[] Args) dans 17d14f5c-a337-4978-8281-53493378c1071.vb:ligne 81 à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() à System.Threading.ThreadHelper.ThreadStart_Context(Object state) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) à System.Threading.ThreadHelper.ThreadStart()
La table utilisée ici est EFFECTUER(Numpilote, Numavion, Numtrajet, Datevol, Heuredep, Heurearriv)
Merci pour votre aide
A voir également:
Erreur au niveau de la suppression et de la modification