I am trying to write some code that takes a .csv file and inserts it into SQL.

I am having issues with it reading the header. I would like to be able to leave 
the header on the file and not have it insert the header data into the DB.

When I try to run it without a header I am having issues with it reading the 
number of elements wrong. It is getting confused when a line has blank data for 
the element.

So it see following line as only having 8 elements when it should have 13:

,Zachary,Abbott,D.O.,,1720 Northbrook Drive,,Ann Arbor,MI,48103,[EMAIL 
PROTECTED],,

Here is my code:

<cffile action="read" file="#file1#" variable="fileData">

<cfloop list="#fileData#" delimiters="#Chr(10)##Chr(13)#" index="record">

<cfquery name="qryInsert" datasource="physleads">

INSERT INTO contacts (prefix, firstName, lastName, suffix, companyName, 
address, address2, city, state, zipCode, phone, fax, email)
values (
 #listgetat('#record#',1, ',')#'
 #listgetat('#record#',2, ',')#'
 #listgetat('#record#',3, ',')#'
 #listgetat('#record#',4, ',')#'
 #listgetat('#record#',5, ',')#'
 #listgetat('#record#',6, ',')#'
 #listgetat('#record#',7, ',')#'
 #listgetat('#record#',8, ',')#'
 #listgetat('#record#',9, ',')#'
 #listgetat('#record#',10, ',')#'
 #listgetat('#record#',11, ',')#'
 #listgetat('#record#',12, ',')#'
 #listgetat('#record#',13, ',')#'
) 
                              
</cfquery>

</cfloop>

Any help with this would be great.

Thanks.





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Download the latest ColdFusion 8 utilities including Report Builder,
plug-ins for Eclipse and Dreamweaver updates.
http;//www.adobe.com/cfusion/entitlement/index.cfm?e=labs%5adobecf8%5Fbeta

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:287065
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to