I've been doing some reseach on how to do this, but haven't been able to find a very simple example - like my case is.
I have one CSV file that I would like to import into an Access database (2010).
I have created the database file and a table named "MainTable", and have my CSV file formatted and with data in it. This is the code that I have been putting together, although it comes up with an error:Exception calling "Open" with "0" argument(s): Unrecognized database format...
# Imports data collected into an Access database.
$dbFile = "C:\ScheduledCodeRun\CollatedData\Database.accdb"
$dataFile = "C:\ScheduledCodeRun\CollatedData\CollatedData.csv"
$Conn = New-Object System.Data.OleDb.OleDbConnection($ConnectString)
$Conn.Open()
Get-Content $dataFile | ForEach
{
$cmd = $Conn.CreateCommand()
$cmd.CommandText = "INSERT maintable VALUES ($_.col1, $_.col2, $_.col3)"
$cmd.ExecuteNonQuery()
}
$Conn.Close()
$Conn
Thank you for any help.