Someone help me... I need a way, other then using DTS to insert data into a
SQL table.  I was able to find some code on easyCFM.com, and it works, but
only with comma delimited files.  What I need to know is how I might be able
to correct this so I can use files with other delimiters.

Below is the text file and code.  The way it is now, it works fine.  When I
change the delimiter from a comma ',' to say tilde '~' in the file and the
code, I bombs!

test.txt file:

20070510,Joe Smith, 312-555-1212,32121
20070510,Mary Smith, 312-555-1212,32121
20070509,John Doe, 413-555-4312,54331
20070508,Mike Cole, 541-555-9119,21112
20070504,Jane Short, 801-555-1332,73124



=====================================
Here's the code:

<!--- get and read the TXT file --->
<cffile action="read" file="test.txt" variable="txtfile">

<!--- loop through the TXT file on line breaks and insert into database --->
<cfloop index="index" list="#txtfile#" delimiters="#chr(10)##chr(13)#">
    <cfquery name="importtxt" datasource="sqlconnect">
         INSERT INTO testload (date_add,name,phone,zip)
         VALUES
                  ('#listgetAt('#index#',1, '|')#',
                   '#listgetAt('#index#',2, '|')#',
                   '#listgetAt('#index#',3, '|')#',
                   '#listgetAt('#index#',4)#'
                  )
   </cfquery>
</cfloop>

<!--- use a simple database query to check the results of the import -
dumping query to screen --->
<cfquery name="rscsvdemo" datasource="sqlconnect">
         SELECT * FROM testload
</cfquery>
<cfdump var="#rscsvdemo#">

================================

Someone help!!  How do I fix it to work with other delimiters?  I get the
below error if I can the comma to say a pipeline '|'.  I made sure to change
the test.txt file to match.

 Invalid list index 4.  In function ListGetAt(list, index [, delimiters]),
the value of index, 4, is not a valid as the first argument (this list has 1
elements). Valid indexes are in the range 1 through the number of elements
in the list.    The error occurred in *testload.cfm: line 15*

13 :                    '#listgetAt('#index#',2, '|')#',
14 :                    '#listgetAt('#index#',3, '|')#',
*15 :                    '#listgetAt('#index#',4)#'*
16 :                   )
17 :    </cfquery>


================================

Thanks all!!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion MX7 and Flex 2 
Build sales & marketing dashboard RIA’s for your business. Upgrade now
http://www.adobe.com/products/coldfusion/flex2?sdid=RVJT

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

Reply via email to