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
| '---- CursorTypeEnum Values ----
Const adOpenForwardOnly = 0 , adOpenKeyset = 1, adOpenDynamic = 2, adOpenStatic = 3
'---- LockTypeEnum Values ----
Const adLockReadOnly = 1, adLockPessimistic = 2, adLockOptimistic = 3, adLockBatchOptimistic = 4
Const ForReading=1, ForWriting =2
'Main
Call UpdateMDB(WScript.Arguments(0),WScript.Arguments(1)
' exemple d'appel :
' updateMDB.vbs "C:\Temp\MaBase.mdb" "C:\Temp\Donnees\clients.txt"
' End Main ------------------------------------------------------
Sub UpdateMDB(PathMDB,PathFile)
Dim DBAccess, Rs, NameField, DataToAdd
'database
Set dbAccess = CreateObject("ADODB.Connection")
StrAccess = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & PathMDB
dbAccess.Open(StrAccess)
'Recordset
Set Rs = CreateObject("ADODB.Recordset")
Rs.CursorType = adOpenStatic
Rs.LockType = adLockOptimistic
Rs.Open "SELECT * FROM TableClient" , Straccess
Rs.AddNew
'Text file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FileRead = FSO.openTextFile(PathFile ,ForReading, True)
Do While Not FileRead.AtEndOfStream
NameField = FileRead.ReadLine ' lecture ligne impaire = nom du champ
DataToAdd = FileRead.ReadLine ' lecture ligne paire = donnée correspondante
' fill database fields
Rs.Fields(NameField) = DataToAdd
Loop
FileRead.Close
Next
Rs.Update
Rs.Close
Set Rs = Nothing
dbaccess.Close
Set dbaccess= Nothing
End Sub |
Partager