- '---- 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
'---- 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