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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
Dim DTAVMaj As New DataView
Dim DTARV As DataRowView
Dim lire As OleDbDataReader
DTAVMaj.Table = DTable
Dim lot As String
DTAVMaj.RowStateFilter = DataViewRowState.Added Or DataRowState.Modified
For Each DTARV In DTAVMaj 'dtarv contient la ligne ajoutée, modifiée ou supprimée
Select Case DTARV.Row.RowState
Case DataRowState.Added
command.Connection.Open()
command.CommandText = "select IdLot From Lot Where Nom = '" & DTARV.Row.Item(11) & "'"
Dim red As OleDbDataReader
red = command.ExecuteReader
red.Read()
lot = red.GetValue(0)
red.Close()
command.CommandText() = "INSERT INTO Personne (Nom, Prenom, RaisonSociale, Entite, Adresse, CP, Ville, Tel, Fax, Mail)" _
& " VALUES ('" & DTARV.Row.Item("Nom") & "', '" & DTARV.Row.Item("Prenom") & "', '" & DTARV.Row.Item("RaisonSociale") & "'," _
& " '" & Replace(DTARV.Row.Item("Entite"), "'", "''") & "','" & DTARV.Row.Item("Adresse") & "','" & DTARV.Row.Item("CP") & "'," _
& " '" & DTARV.Row.Item("Ville") & "','" & DTARV.Row.Item("Tel") & "','" & DTARV.Row.Item("Fax") & "'," _
& " '" & DTARV.Row.Item("Mail") & "','" & lot & "')"
command.ExecuteNonQuery()
command.CommandText() = "select max(IdPersonne) from Personne"
lire = command.ExecuteReader
lire.Read()
idpe = lire.GetValue(0)
lire.Close()
nom = DTARV.Row.Item("Nom")
prenom = DTARV.Row.Item("Prenom")
rs = DTARV.Row.Item("RaisonSociale")
ent = DTARV.Row.Item("Entite")
command.Connection.Close()
Case DataRowState.Modified
command.Connection.Open()
command.CommandText = "select IdLot From Lot Where Nom = '" & DTARV.Row.Item(11) & "'"
Dim red As OleDbDataReader
red = command.ExecuteReader
red.Read()
lot = red.GetValue(0)
red.Close()
command.CommandText = "UPDATE Personne SET Nom = '" & DTARV.Row.Item("Nom") & "', Prenom = '" & DTARV.Row.Item("Prenom") & "'," _
& " RaisonSociale = '" & DTARV.Row.Item("RaisonSociale") & "', Entite = '" & Replace(DTARV.Row.Item("Entite"), "'", "''") & "'," _
& "Adresse = '" & DTARV.Row.Item("Adresse") & "', CP = '" & DTARV.Row.Item("CP") & "', Ville = '" & DTARV.Row.Item("Ville") & "'," _
& "Tel = '" & DTARV.Row.Item("Tel") & "', Fax = '" & DTARV.Row.Item("Fax") & "', Mail = '" & DTARV.Row.Item("Mail") & "'," _
& "IdLot = '" & lot & "'"
command.ExecuteNonQuery()
command.Connection.Close()
End Select
Next
Dim selec As DataGridViewSelectedRowCollection
selec = DataPersNiv.SelectedRows
For Each lignes As DataGridViewRow In selec 'Insere dans G toutes les lignes selectionnées par l'utilisateur
command.Connection.Open()
If Principal.Modounewo = "newo" Then
command.CommandText = "insert into G (IdBat, IdPersonne) values (" & NouveauBat1.IdBat & ", " & lignes.Cells.Item(0).Value & ")"
ElseIf Principal.Modounewo = "mod" Then
command.CommandText = "insert into G (IdBat, IdPersonne) values (" & ModifBat.numBat & ", " & lignes.Cells.Item(0).Value & ")"
End If
command.ExecuteNonQuery()
command.Connection.Close()
Next
Call NouveauBat5.remplirLVmod()
Me.Close()
End If |
Partager