Skip to main content
Known Participant
May 6, 2009
Question

error for the uploading csv file to database

  • May 6, 2009
  • 3 replies
  • 1728 views

Hi i tried to upload the csv file to database and i am getting error as

<cffile action="read" file="#data_dir_upload#/di_audit_corp_upc_ldr_tbl.csv" variable="di_audit_corp_upc_ldr_tbl">
<!--- loop through the CSV-TXT file on line breaks and insert into database --->
<cfloop index="index" list="#di_audit_corp_upc_ldr_tbl#" delimiters="#chr(10)##chr(13)#">
    <cfquery  datasource="#request.dsnCAO#">   
            <!--- SET ANSI_WARNINGS OFF      --->
         INSERT INTO [dbo].[di_audit_corp_upc_ldr_tbl]
                            ( cpt_dpt_cd,cpt_com_cd,sub_com_cd,con_upc_no,pid_lng_dsc_tx,pid_sht_dsc_tx)
         VALUES
                  (<cfqueryparam value='#left(trim(listgetAt('#index#',2,',')),2)#' cfsqltype="cf_sql_char">,
                   <cfqueryparam value='#left(trim(listgetAt('#index#',3,',')),3)#' cfsqltype="cf_sql_char">,
                   <cfqueryparam value='#left(trim(listgetAt('#index#',4,',')),5)#' cfsqltype="cf_sql_char">,
                   <cfqueryparam value='#left(trim(listgetAt('#index#',1,',')),13)#' cfsqltype="cf_sql_varchar">,                  
                   <cfqueryparam value='#left(trim(listgetAt('#index#',5,',')),25)#' cfsqltype="cf_sql_varchar">,
                   <cfqueryparam value='#left(trim(listgetAt('#index#',6,',')),12)#' cfsqltype="cf_sql_varchar">)    
   </cfquery>
</cfloop>

Error:
An error occurred while executing DTS package to import data.
Invalid list index 6.
In function ListGetAt(list, index [, delimiters]), the value of index, 6, is not a valid as the first argument (this list has 5 elements). Valid indexes are in the range 1 through the number of elements in the list.

i am unable to solve this issue can any one will help me to solve this issue

Thanks,

Kiran

This topic has been closed for replies.

3 replies

Inspiring
May 14, 2009

There are two common issues when importing csv files.  One is empty elements.  The other is commas as part of the data.  You need a strategy to deal with each.

Participant
May 25, 2009

Hi,

      According to my current requirement I want to know   is there simple Flex compatible parser for use in parsing CSV (comma separated value) format files. This may already be available in Flex Builder.  If not what is the best way to parse these files.


Regards

Kalavati Singh

kalavati_singh@yahoo.co.in

June 30, 2009

I take it your are trying to use a csv file to insert new data into a database, using flex and coldfusion?

if so, then I would load the file in flex using cffile in ColdFusion and then use Load Data if you are using MySQL

This can show you more about it.

http://blog.tygate.com/?p=75

We get very large csv files ftp'd to us every week, and we have to load them in to the db. this works for us.

Astonished_protector15C3
Participating Frequently
May 14, 2009

Hi,

Verify Your CSV file is well formatted or not

BKBK
Community Expert
Community Expert
May 8, 2009

Have another look at the text di_audit_corp_upc_ldr_tbl. Coldfusion is convinced it has just 5 lines.