I've done a really basic version of this in
the past, and it's easy enough. This assumes there's no fields wraped in quotes,
but I'm sure you could make it more fool-proof.
Something like this:
<cfloop list="#form.csv_contents#"
delimiters="#chr(13)##chr(10)#" index="this_line">
<cfoutput>
#this_line#<br>
</cfoutput>
<cfset product_ID = ListGetAt(#this_line#,
1)>
<cfset product_name = ListGetAt(#this_line#, 2)>
<cfset product_short_desc = ListGetAt(#this_line#, 3)>
<cfset product_long_desc = ListGetAt(#this_line#, 4)>
<cfset product_name = ListGetAt(#this_line#, 2)>
<cfset product_short_desc = ListGetAt(#this_line#, 3)>
<cfset product_long_desc = ListGetAt(#this_line#, 4)>
<CFQUERY NAME="insert_product"
DATASOURCE="xxxx">
INSERT INTO
tbl_products (product_MerchantProductID, product_Name, product_Description, product_ShortDescription, product_OnWeb)
VALUES
(<cfqueryparam value="#product_ID#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">,
<cfqueryparam value="#product_name#" cfsqltype="CF_SQL_VARCHAR" maxlength="125">,
<cfqueryparam value="#product_long_desc#" cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value="#product_short_desc#" cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value="1" cfsqltype="CF_SQL_INTEGER">)
</CFQUERY>
INSERT INTO
tbl_products (product_MerchantProductID, product_Name, product_Description, product_ShortDescription, product_OnWeb)
VALUES
(<cfqueryparam value="#product_ID#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">,
<cfqueryparam value="#product_name#" cfsqltype="CF_SQL_VARCHAR" maxlength="125">,
<cfqueryparam value="#product_long_desc#" cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value="#product_short_desc#" cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value="1" cfsqltype="CF_SQL_INTEGER">)
</CFQUERY>
</cfloop>
hth
gav
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "CFAussie Mailing List" <[EMAIL PROTECTED]>
Sent: Friday, May 28, 2004 1:05 PM
Subject: [cfaussie] RE: reading a csv
file
>
> that's the way I was doing it. I was hoping there was some sort of
> function like csv2query() already implemented :)
>
> Cheers
>
> >>> [EMAIL PROTECTED] 05/28/04 10:52am >>>
>
> I reckon (theoretically) the easiest way would be with OPENQUERY() no
> need for a DSN on the file just read it directly... BANG...
>
>
> -----Original Message-----
> From: Peter Galipo [mailto:[EMAIL PROTECTED]
> Sent: Friday, 28 May 2004 12:48 PM
> To: CFAussie Mailing List
> Subject: [cfaussie] reading a csv file
>
>
> Hi All,
>
> I have a csv file with about 8 columns of data. I would like to read
> this file into a query structure somehow. Is there an easy way to do
> this?
>
> Cheers,
>
> Pete
>
> ---
> You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
> To unsubscribe send a blank email to
> [EMAIL PROTECTED]
>
> MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
> http://www.mxdu.com/ + 24-25 February, 2004
>
> Register now for the 3rd National Conference on Tourism Futures, being
> held in Townsville, North Queensland 4-6 August - www.tq.com.au/tfconf
>
> ---
> You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
>
> To unsubscribe send a blank email to
> [EMAIL PROTECTED]
>
> MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
> http://www.mxdu.com/ + 24-25 February, 2004
>
> ---
> You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
> To unsubscribe send a blank email to [EMAIL PROTECTED]
>
> MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
> http://www.mxdu.com/ + 24-25 February, 2004
> ---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004
