Created
December 19, 2017 11:43
-
-
Save anonymous/39b0cff91c26faca1dcbfba1ad672f27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Call Main() | |
Sub Main() | |
Dim FileSystem | |
Set FileSystem = CreateObject("Scripting.FileSystemObject") | |
Dim TextFile | |
Set TextFile = FileSystem.OpenTextFile("test.csv", 2, True) | |
Call TextFile.WriteLine("id,name,birthday") | |
Call TextFile.Close() | |
Dim Connection | |
Set Connection = CreateObject("ADODB.Connection") | |
Call Connection.Open("DRIVER=Microsoft Access Text Driver (*.txt, *.csv)") | |
Dim Command | |
Set Command = CreateObject("ADODB.Command") | |
Set Command.ActiveConnection = Connection | |
Command.CommandText = "INSERT INTO test.csv VALUES(?, ?, ?)" | |
Call Command.Parameters.Append(Command.CreateParameter("id", 3, 1)) | |
Call Command.Parameters.Append(Command.CreateParameter("name", 200, 1, 10)) | |
Call Command.Parameters.Append(Command.CreateParameter("birthday", 133, 1)) | |
Dim i | |
For i = 1 To 100 | |
Command.Parameters("id").Value = i | |
Command.Parameters("name").Value = "name" & i | |
Command.Parameters("birthday").Value = DateAdd("d", i, Date()) | |
Call Command.Execute() | |
Next | |
Call Connection.Close() | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment