' Le code pour ajouter a la base de données cmd.CommandType = CommandType.Text cmd.CommandText = "INSERT INTO Stagiaires (Nom, Prénom, Date_de_Naissance, Téléphone, Etablissement, Niveau, [Option], Recommandation, Observation, Retenue, [Non_Retenue]) " & " VALUES ('" & TxtNom.Text & "', '" & TxtPrénom.Text & "', '" & DateTimePickerAjouter.Value & "', '" & TxtTéléphone.Text & "', '" & TxtEtablisseement.Text & "', '" & TxtNiveau.Text & "', '" & TxtOption.Text & "','" & TxtRecommandation.Text & "', '" & TxtObservation.Text & "', '" & TxtRetenue.Text & "', '" & TxtNRetenue.Text & "') " cmd.Connection = con cmd.ExecuteNonQuery()
Try If MsgBox(" Voulez Vous vraiment supprimer le stagiaire", 1 + 32, "Confiramtion de la suppression") = MsgBoxResult.Ok Then con.Close() con.Open() cmd.CommandType = CommandType.Text cmd.CommandText = " DELETE FROM Stagiaires WHERE N°=" & Val(TxtNumero.Text) cmd.Connection = con cmd.ExecuteNonQuery() MsgBox("Le stagiaire a été bien Supprimé", MsgBoxStyle.Information, "Confirmation") End If Catch ex As Exception MsgBox(ex.Message) End Try
Dim MaCmd As ADODB.Command Set MaCmd = New ADODB.Command Dim As sQuery String sQuery="DELETE * FROM Stagiaires WHERE N°=" & _ Cint(TxtNumero.Text) ' si N° est un Entier ' CLng(TxtNumero.Text) si N° est un Long ' l' utilisation de Val() est à éviter dans ce contexte. If con.State = 0 Then con.Open con.BeginTrans With MaCmd .ActiveConnection = con .CommandType = adCmdText .CommandText = sQuery .Execute End With con.CommitTrans Même chose pour l' ajout.Tu dois suivre le même schéma.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question