Jag har ett problem med en DataGridView där jag försöker uppdatera en rad i griden, när jag uppdaterar den första raden så fungerar allt OK, men när jag för söker uppdatera nästa rad så finns fortfarande den första raden kvar i minnet. Jag är tacksam för tips hur detta kan åtgärdas.DataGridView
Module ModDBupdate
Dim test1, test2, test3, test4, test5, test6 As String
Public Sub Save_changes_in_BENJEXP_kollityper()
PostExist = False
If frmADMIN.dgvKolliTyper.CurrentRow.Cells(0).Value > 0 Then PostExist = True
If RowDelete = True Then
CONN3.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & BENJdbs & ";Jet OLEDB:Database Password=xxxxx")
DATA3CMD.ActiveConnection = CONN3
If PostExist = True Then
CONN3.BeginTrans()
DATA3CMD.CommandText = "DELETE FROM Kollityp WHERE ID = " & RowIndex & ""
DATA3CMD.Execute()
CONN3.CommitTrans()
End If
CONN3.Close()
End If
If RowDelete = False Then
CONN3.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & BENJdbs & ";Jet OLEDB:Database Password=xxxxx")
DATA3CMD.ActiveConnection = CONN3
'frmADMIN.dgvKolliTyper.Rows(test1).Cells(3).Value
test1 = "" & frmADMIN.dgvKolliTyper.CurrentRow.Index
test2 = "" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(2).Value
test3 = "" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(3).Value
test4 = "" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(4).Value
test5 = "" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(5).Value
test6 = "" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(6).Value
If PostExist = True Then
CONN3.BeginTrans()
DATA3CMD.CommandText = "UPDATE Kollityp SET CDT = '" & Today & "', " & _
"LPL = '" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(2).Value & "', " & _
"KAS = '" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(3).Value & "', " & _
"KTY = '" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(4).Value & "', " & _
"KTB = '" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(5).Value & "', " & _
"PRIN = '" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(6).Value & "' " & _
"WHERE ID = " & RowIndex & ""
DATA3CMD.Execute()
CONN3.CommitTrans()
End If
If PostExist = False Then
CONN3.BeginTrans()
DATA3CMD.CommandText = "INSERT INTO Kollityp (UDT, LPL, KAS, KTY, KTB, PRIN) VALUES " & _
"('" & Today & "'" & _
",'" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(2).Value & "'" & _
",'" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(3).Value & "'" & _
",'" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(4).Value & "'" & _
",'" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(5).Value & "'" & _
",'" & frmADMIN.dgvKolliTyper.CurrentRow.Cells(6).Value & "')"
DATA3CMD.Execute()
CONN3.CommitTrans()
End If
CONN3.Close()
End If
Call Load_frmAdmin_KolliTyp()
End Sub
End Module