Note that there are some explanatory texts on larger screens.

plurals
  1. POSpecify target columns on import (CSV to Access)
    primarykey
    data
    text
    <p>I've found out how to import a CSV into my Access database via <a href="https://stackoverflow.com/questions/213657/how-to-read-csv-files-line-by-line-in-vbscript"><strong>another question</strong></a>. But in the <a href="https://stackoverflow.com/questions/213657/how-to-read-csv-files-line-by-line-in-vbscript/213739#213739"><strong>answer</strong></a> there is no information on how to target specific columns upon import. How can I be sure that the correct columns from the CSV get placed into the correct columns in my database?</p> <p>I need to be able to edit/add-to the column values as they get imported <strong>using classic ASP</strong>. Examples:</p> <ul> <li>The 4th column in the CSV is a userid, I need to be able to add "@domain.com" to the end as it enters the database for an email column. </li> <li>The 6th column is a classification: if it's value is "Teacher" then, as it gets imported, I need to change it to "Classroom".</li> </ul> <p>I'm working with some old code &amp; DB's that I didn't create. Believe me, I'd be using something else if I could, <em>so no pot-shots for using MS Access, please.</em></p> <p><strong>I guess this whole thing boils down to this:</strong> </p> <ul> <li>if the <a href="https://stackoverflow.com/questions/213657/how-to-read-csv-files-line-by-line-in-vbscript/213739#213739"><strong>previous question's answer</strong></a> really allows me to treat the CSV the same as a db table, then how can I select the columns as in a real db table?</li> </ul> <p><br/></p> <h1>// Update:</h1> <p>I've set everything up how I <em>believe</em> it should be, but I'm receiving an error:</p> <pre><code>ADODB.Recordset error '800a0bb9' Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. /datazone_bkup/Rollover/importTeachers.asp, line 12 </code></pre> <p>line 12: <code>CSV.open "SELECT * FROM teachers.csv", conn</code></p> <p>My full code is as follows:</p> <pre><code>strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &amp;_ Server.MapPath("\path\to\file") &amp; ";Extended Properties='text;HDR=no;FMT=Delimited';" Set connCSV = Server.CreateObject("ADODB.Connection") connCSV.Open strConn Set CSV = Server.CreateObject("ADODB.recordset") CSV.open "SELECT * FROM teachers.csv", conn do until CSV.eof UserName = CSV.Fields(4) LastName = CSV.Fields(1) FirstName = CSV.Fields(2) MiddleName = CSV.Fields(3) School = CSV.Fields(5) if CSV.Fields(6) = "Teacher" then SecLevel = "Classroom" end if Active = "Yes" TeacherNumber = rsCSV.Fields(0) rsCSV.movenext sql = "INSERT INTO tblTeacher (UserName, LastName, FirstName, MiddleName, School, SecLevel, Active, TeacherNumber) " &amp;_ "VALUES (" &amp;_ "'" &amp; UserName &amp; "','" &amp; LastName &amp; "','" &amp; FirstName &amp; "','" &amp; MiddleName &amp; "'," &amp;_ "'" &amp; School &amp; "','" &amp; SecLevel &amp; "','" &amp; Active &amp; "','" &amp; TeacherNumber &amp; "'" &amp;_ ")" on error resume next conn.execute(sql) loop </code></pre> <p><strong>@HansUp</strong>, when I tried using the <code>!</code> as in <code>rsDB!UserName</code>, I received a <code>Syntax Error</code>. So I went back to setting variables for the CSV column values.</p> <p>Again, thanks for any help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload