1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Rep Power

    Inserting .csv file data into access, cfhttp problem

    I am attempting to write a little app that will allow a user (me) to upload an excel spreadsheet converted into a .csv file, and then the app will read it, and load it up into a table in an access database. (database is not my choice.. project was already developed using it when I took over)

    Right now, I am trying to use cfhttp functions to read the file and create a query so I can then use that information to insert the data into the database.

    This is my code, and I will post my error after it.


    <cffile action="DELETE" file="#FORM.attachment_1#"/>
    <!--- File delete error. --->
    <!--- no errors with the file upload so lets upload it--->
    <cffile action="upload"
                     accept = ""
    <cfset svrFile = "#myResult.ServerDirectory#"&"\"&"#myResult.ServerFile#"/>
    <cfset dataUrl = ("http://" &cgi.server_name & getDirectoryFromPath( cgi.script_name ) & "svrFile") />
    <cfhttp url="#dataUrl#" name="employee" columns="siteID,empstatus,empfirstname,empmiddlename,emplastname,empnickname,emplocation,empgender,empdob,empdoh,empee" delimiter="#chr(32)#" resolveurl="no" />
    <cfdump var="#employee#" label="CSV Query" />
    right now, I am just trying to dump the query from the cfhttp function... I will get to the insert after I fix this..

    This is my error:

    Incorrect number of columns in row.
    Verify the number of columns specified in the columns attribute and in the target file

    The error occurred in C:\websites\211562fe3\partners\cfm\csvUploadAction.cfm: line 40

    38 : <cfset svrFile = "#myResult.ServerDirectory#"&"\"&"#myResult.ServerFile#"/>
    39 : <cfset dataUrl = ("http://" &cgi.server_name & getDirectoryFromPath( cgi.script_name ) & "svrFile") />
    40 : <cfhttp url="#dataUrl#" name="employee" columns="siteID,empstatus,empfirstname,empmiddlename,emplastname,empnickname,emplocation,empgender,e mpdob,empdoh,empee" delimiter="#chr(32)#" resolveurl="no" />
    41 :
    42 : <cfdump var="#employee#" label="CSV Query" />

    I don't get it... these are the fields in the .csv file, how do I verify the correct number?

    Can anyone help me figure this out?
    Thank you.
  2. #2
  3. No Profile Picture

    Join Date
    Jun 2002
    Raleigh, NC
    Rep Power
    Honestly, I'm not really sure what you're trying to do here. Uploading a CSV and then immediately trying to make an HTTP call to it? Is this just some experiment, or is there some reason you would do this and not just manipulate the CSV file you already have in memory?

    That said, I would confirm that you can actually request the file in your browser directly. Make sure the values in the file match the number and values you're expecting, and that there is no other whitespace or content being displayed when the file is requested. You can also dump the value you're using for the URL to make sure it is what you're expecting it to be.

IMN logo majestic logo threadwatch logo seochat tools logo