3 Replies Latest reply on Jul 28, 2009 9:05 AM by Dan Bracuk

    Import Help

    -Matthew-

      Trying to import data...couple of questions. Below is my code.

       

      1. How do I handle commas or extras in fields?

      2. How can I change the date on import to make sure its yyyy/mm/dd?

       

      <cfif IsDefined("FORM.import") AND #FORM.import# NEQ "">
        <CFFILE ACTION="upload" DESTINATION="E:\Apache2.2\htdocs\sites\smart\calendar\administration\import-events" FILEFIELD="file1" NAMECONFLICT="makeunique">
          <cfset file1="#File.ServerFileName#.#File.ServerFileExt#">
         
        <cffile action="read" file="E:\Apache2.2\htdocs\sites\smart\calendar\administration\import-events\#file1#" variable="csvfile"> 
         
        <!--- loop through the CSV-TXT file on line breaks and insert into database --->
         
        <cfloop index="index" list="#csvfile#" delimiters="#chr(10)##chr(13)#">
          <cfquery name="importcsv" datasource="#DSN#">
               INSERT INTO events (event_name,event_description,event_location,event_time, event_date,event_schoolid )
               VALUES
                        ('#listgetAt('#index#',1, ',')#',
                         '#listgetAt('#index#',2, ',')#',
                         '#listgetAt('#index#',3, ',')#',
                         '#listgetAt('#index#',4, ',')#',
                         '#listgetAt('#index#',5, ',')#',
                         '#listgetAt('#index#',6, ',')#'
                        )
         </cfquery>
         <cfoutput>#index#</cfoutput>
        </cfloop>
          </cfif>