Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'si on a ouvert le form en mode modif alors ... If Me.typemiseajour = TypeMaj.modification Then Try 'instance connection Dim conn As New OleDbConnection("provider=microsoft.jet.oledb.4.0; data source=" & Application.StartupPath & "\gestionstock.mdb") 'instance commande + type + commandText Dim CmdInsert As New OleDbCommand CmdInsert.CommandType = CommandType.Text CmdInsert.CommandText "update materiel set id_mat '" & txt_num.Text & "', Nom_mat = '" & txt_nom.Text & "', Marque =" & txt_marque.Text & ", Caracteristique = '" & txt_carac.Text & "' where Id_mat = " & Integer.Parse(txt_num.Text) CmdInsert.Connection = conn conn.Open() 'execution de la requette de Mise a jour UPDATE CmdInsert.ExecuteNonQuery() conn.Close() MsgBox("modifié avec succés", MsgBoxStyle.Information, "modification de Materiel") Me.Close() 'retour au form d'aceuilade frmContacts.Show() Catch ex As Exception MessageBox.Show("l'erreur suivante s'est produite lors de la tentative de modification:" & vbCrLf & ex.Message & vbCrLf & "erreur dans : " & ex.Source, "ERREUR", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End Try Else 'sinon le form doit etre ouvert en mode ajout 'selon la declaration de l'enumeration TypeMaj Try 'idem instance connection ... commande..puis execution 'de la requette d'ajout INSERT Dim conn As New OleDbConnection("provider=microsoft.jet.oledb.4.0; data source=" & Application.StartupPath & "\gestionstock.mdb") Dim CmdInsert As New OleDbCommand CmdInsert.CommandType = CommandType.Text CmdInsert.CommandText = "insert into contact(nom,email,tel,adresse) values ('" & txt_num.Text & "', '" & txt_nom.Text & "'," & txt_marque.Text & ",'" & txt_carac.Text & "')" CmdInsert.Connection = conn conn.Open() CmdInsert.ExecuteNonQuery() conn.Close() MsgBox("ajouté avec succés", MsgBoxStyle.Information, "ajout de Materiel") Me.Close() frmContacts.Show() Catch ex As OleDbException MessageBox.Show("l'erreur suivante s'est produite lors de la tentative d'ajout:" & vbCrLf & ex.Message & vbCrLf & "erreur dans : " & ex.Source, "ERREUR", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End Try End If End Sub
CmdInsert.CommandText = "update materiel " & _ " set id_mat = '" & txt_num.Text & "', " & _ " Nom_mat = '" & txt_nom.Text & "', " & _ " Marque =" & txt_marque.Text & ", " & _ " Caracteristique = '" & txt_carac.Text & "' " & _ " where Id_mat = " & Integer.Parse(txt_num.Text)Dans cette requète, tu utilises le champ id_mat dans les "set" ainsi que dans la clause "Where" : Or, tu traites différemment le champ dans ces deux utilisations :
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionj'utulise Acces 2007 et ma base sans mot de passe