1

I am looking for a code example or logical flow for taking a CSV file and importing it into an MS Access DB.

I have some powershell scripts which use the export-csv and I am currently importing these into access manually. My goal is to fully automate the process in access.

I have powershell code to create the tables ahead of time, so that is not an issue for me.

1 Answer 1

1

Here is the answer you are looking for:

http://www.techtalkz.com/microsoft-windows-powershell/155962-using-import-csv-post-entries-access-db.html

There isn't much I can add to what is already explained by a couple of excellent Powershell pros.

Here is the relevant post:

you can use ADO to connect to access :

see for an example : http://mow001.blogspot.com/2006/02/s...h-answers.html

you can use the out-datatable from here to convert the CSV to a dataset :

http://mow001.blogspot.com/2006/05/p...pdate-and.html

then you can use a dataadapter to write back the datatable : here is an helperfunction I mostly use for this :

function get-DataAdapter ($SelectCMD){ $da = new-object System.Data.SqlClient.SQLDataAdapter($SelectCMD) $scb = New-Object System.Data.SqlClient.SqlCommandBuilder($da) $da.UpdateCommand = $scb.GetUpdateCommand() $da.InsertCommand = $scb.GetInsertCommand() $da.DeleteCommand = $scb.GetDeleteCommand() $da }

now you can write back by using this command :

$da.update($Table)

You will have to adapt the helper function to use oledb instead of the SQLDataAdapter since you are talking to Access but that should be the easy part. These guys did the legwork for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.