Skip navigation
pmlink360
Currently Being Moderated

CFspreadsheet issue

Aug 11, 2012 3:33 PM

Hello, I have a question about CFspreadsheet....

 

 

I'm reading a spreadsheet and inserting the data into  a SQL server  DB....everything works fine unless 1 of my columns in the spreadsheet is blank. I'm getting the following error:

 

 

Element PHONE is undefined in EXCELQUERYBYNAME.

 

 

I tried the put a cfif isdefined to see if that would solve it but no luck....same error message. How can I handle this issue? My cfquery is below:

 

 

<cfquery name="insert_Sh_data" datasource="#datasource#">

    INSERT into contactrecord

       (

       contact_date,

       fname,

       lname,

       address,

       city,

       state,

       zip,

       county,

       <cfif isDefined(excelQueryByName.phone)>phone,</cfif>

       <cfif isDefined(excelQueryByName.cell)>cell,</cfif>

       <cfif isDefined(excelQueryByName.fax)>fax,</cfif>

       <cfif isDefined(excelQueryByName.title)>title,</cfif>

       <cfif isDefined(excelQueryByName.organization)>organization,</cfif>

       <cfif isDefined(excelQueryByName.email)>email,</cfif>

       <cfif isDefined(excelQueryByName.general_comments)>general_comments,</cfif>

       <cfif isDefined(excelQueryByName.fname2)>fname2,</cfif>

       <cfif isDefined(excelQueryByName.lname2)>lname2,</cfif>

        mailing,

        input_by,

        input_date,

        input_time,

        input_by_id,

        country,

        sh_rating

        ) 

                          

        Values(              

        '#Trim(excelQueryByName.contact_date)#',

        '#Trim(excelQueryByName.fname)#',

        '#Trim(excelQueryByName.lname)#',

        '#Trim(excelQueryByName.address)#',

        'Trim(excelQueryByName.city)#',

        '#Trim(excelQueryByName.state)#',

        '#Trim(excelQueryByName.zip)#',

        '#Trim(excelQueryByName.county)#',

        <cfif isDefined(excelQueryByName.phone)>'#Trim(excelQueryByName.phone)#',</ cfif>

        <cfif isDefined(excelQueryByName.cell)>'#Trim(excelQueryByName.cell)#',</cf if>

         <cfif isDefined(excelQueryByName.fax)>'#Trim(excelQueryByName.fax)#',</cfif >

         

         <cfif isDefined(excelQueryByName.title)>'#Trim(excelQueryByName.title)#',</ cfif>

         <cfif isDefined(excelQueryByName.organization)>'#Trim(excelQueryByName.orga nization)#',</cfif>

         <cfif isDefined(excelQueryByName.email)>'#Trim(excelQueryByName.email)#',</ cfif>

         <cfif isDefined(excelQueryByName.general_comments)>'#Trim(excelQueryByName. general_comments)#',</cfif>

         <cfif isDefined(excelQueryByName.fname2)>'#Trim(excelQueryByName.fname2)#', </cfif>

         <cfif isDefined(excelQueryByName.lname2)>'#Trim(excelQueryByName.lname2)#', </cfif>

         '#Trim(excelQueryByName.mailing)#',

         '#Trim(excelQueryByName.input_by)#',

         '#Trim(excelQueryByName.input_date)#',

         '#Trim(excelQueryByName.input_time)#',

         '#Trim(excelQueryByName.input_by_id)#',

         '#Trim(excelQueryByName.country)#',

         '#Trim(excelQueryByName.sh_rating)#'

         )

</cfquery>

 

 

 

 

Thanks in Advance.

 
Replies
  • Currently Being Moderated
    Aug 11, 2012 3:54 PM   in reply to pmlink360

    Instead of checking to see if the field is defined, check to see if the length is greater than 0.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 13, 2012 12:06 AM   in reply to pmlink360

    The error "Element PHONE is undefined in EXCELQUERYBYNAME." indicates that the 'phone' column doesn't exist in the query object. Which I guess means the phone column doesn't exist in the Excel spreadsheet.

     

    What do you see when you dump EXCELQUERYBYNAME? Can you see the phone column?

     

    In theory you could use:

     

    <cfif StructKeyExists(EXCELQUERYBYNAME, "phone")>phone,</cfif>

     

    Even if the object isn't actually a Struct.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 2:55 PM   in reply to pmlink360

    You need to put your parameter in quotes when using isDefined, like so:

     

    cfif isDefined("excelQueryByName.phone")>phone,</cfif>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points