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
|
Dim DataV As DataView
Dim DataRV As DataRowView
Dim conn As New OleDb.OleDbConnection(CsV.strconn)
Dim Comm As New OleDbCommand
Dim SCmd As String
DataV = New DataView
DataV.Table = ds.Tables("Time")
Comm.Connection = conn
'Comm.CommandText = SCmd
Comm.CommandType = CommandType.Text
conn.Open()
DataV.RowStateFilter = DataViewRowState.Added Or DataViewRowState.Deleted Or DataViewRowState.ModifiedCurrent
For Each DataRV In DataV
Select Case DataRV.Row.RowState
Case DataRowState.Added
With DataRV
SCmd = "INSERT INTO Table (Champ1, Champ2, Champ3, Champ4, Champ5, Champ6) "
SCmd &= String.Format("VALUES ('{0}', #{1}#, '{2}', '{3}', '{4}', '{5}') ", .Item(0), .Item(1), .Item(2), .Item(3), .Item(4), .Item(5))
Comm.CommandText = SCmd
Comm.ExecuteNonQuery()
End With
Case DataRowState.Deleted
With DataRV
SCmd = "DELETE FROM Table "
SCmd &= String.Format("WHERE Champ1 = '{0}' And Champ2 = #{1}# And Champ3 = '{2}' And Champ4 = '{3}' And Champ5 = '{4}' And Champ6 = '{5}' ", .Item(0), .Item(1), .Item(2), .Item(3), .Item(4), .Item(5))
Comm.CommandText = SCmd
Comm.ExecuteNonQuery()
End With
Case DataRowState.Modified
With DataRV
SCmd = "UPDATE Table "
SCmd &= String.Format("SET Champ1 = '{0}', Champ2 = #{1}#, Champ3 = '{2}', Champ4 = '{3}', Champ5 = '{4}', Champ6 = '{5}' ", .Item(0), .Item(1), .Item(2), .Item(3), .Item(4), .Item(5))
SCmd &= String.Format("WHERE Champ1 = '{0}' And Champ2 = #{1}# And Champ3 = '{2}' And Champ4 = '{3}' And Champ5 = '{4}' And Champ6 = '{5}' ", .Item(0), .Item(1), .Item(2), .Item(3), .Item(4), .Item(5))
Comm.CommandText = SCmd
Comm.ExecuteNonQuery()
End With
End Select
Next
ds.Tables("Time").AcceptChanges()
conn.Close() |
Partager