Unable to Execute Insert Query using cfquery

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Unable to Execute Insert Query using cfquery

    Hi

    I am using coldfusion MX and backend MS-Access.I want to import the data from
    excel file.so i am saving as Tablimited Text file and Retreving the data.Now i
    want this data to be inserted into database. Select Queries are executing but
    Insert Queries were not getting executed inside the loop.Can Anybody have an
    idea please give me an idea.

    Thanks & Regards
    srinivas

    srimtm Guest

  2. Similar Questions and Discussions

    1. unable to execute a javascript in a dynamically generated HTML
      Hi, I have a dynamically generated HTML code rendered on a browser instance created though code (AxSHDocVw.AxWebBrowser instance) . I have...
    2. cfquery insert into sql statement
      Hello, I have a simple SQL statement (within a cfquery tag) that will not insert: <cfquery datasource="shoptrak" name="insert"> INSERT INTO...
    3. ColdFusion+cfquery+Oracle+CLOB+"Query of Query"
      Error message is: Query Of Queries runtime error. Unsupported SQL type "java.sql.Types.CLOB". My database table: RESMIGAZETEFIHRISTI: ...
    4. insert data in 2 differents tables in same cfquery
      Hi! I have problem with a special odbc driver that only permit me to insert data if insert data in table1 and after in table2.... Something like:...
    5. Unable to execute shell commands
      Windows 2003 ISS 6.0 That's your problem ;) try using: Linux Debain Apache 1.3 Then it will execute the shell commands. windows does not...
  3. #2

    Default Re: Unable to Execute Insert Query using cfquery

    Can you post your code and any error messages and maybe someone can help you?
    mxstu Guest

  4. #3

    Default Re: Unable to Execute Insert Query using cfquery

    pasting the whole page like this is not much help

    All we need is the code for the select and insert that is not working and any
    error(s) that occur.

    I did start to scan through the code, then when I had to start srolling
    up/down/sideways I gave up, but I did notice

    You have a number of these
    <cfif not IsDefined("pg")><cfset ............

    You can just use

    <cfparam name="pg" default="default value">

    Ken

    The ScareCrow Guest

  5. #4

    Default Re: Unable to Execute Insert Query using cfquery

    Hi ken

    Thank you for ur suggestion. i am giving my code in brief here..can you go
    thorough once and try to help me out if possible

    <cfloop index="record" list="#String#" delimiters="#chr(13)##chr(10)#">
    <cftry>
    <cfif #listgetat(record,19,chr(9))# eq 0>
    </cfif>
    <cfcatch type="expression">
    <cfset #number# = #cfcatch.ErrNumber#>
    <cfset #message# = #cfcatch.message#>
    <cfif #number# eq 0 or #message# eq ''>
    <cflocation url="import-customers.cfm?sid=#sid#&pg=4">
    </cfif>
    </cfcatch>
    </cftry>
    <cfif #listgetat(record,19,chr(9))# neq 'AMOUNT'>
    <cftry><cfset the_inv_date =
    CreateODBCDateTime("#listgetat(record,2,chr(9))#") ><cfcatch><cfset the_inv_date
    = "NULL"></cfcatch></cftry>
    <cfset #the_invoicenum#=REReplace(Trim("#listgetat(record ,3,chr(9))#"),
    "[^0-9]", "", "ALL")>
    <cfset the_customer = Trim("#listgetat(record,4,chr(9))#")>
    <cfset #the_amount#="#listgetat(record,19,chr(9))#">

    <!--- ### Proceed? ### --->
    <cfif the_customer is not "">

    <!--- ### Retrieve Customer Information ### --->
    <cfquery name="temp" dbtype="ODBC" datasource="#global.dsn#"
    username="#global.dsnusername#" password="#global.dsnpassword#">
    SELECT Customers.CustomerID
    FROM (Customers INNER JOIN Contacts ON Customers.ContactID =
    Contacts.ContactID)
    WHERE (Contacts.Organization = '#the_customer#')
    </cfquery>

    <cfset customerid = temp.CustomerID>
    <!--- ### Create Customer ### --->
    <cfif temp.RecordCount is 0>
    <!--- ### Retrieve ContactID ### --->
    <cfquery name="temp" dbtype="ODBC" datasource="#global.dsn#"
    username="#global.dsnusername#" password="#global.dsnpassword#">SELECT
    Max(ContactID) AS MaxNum FROM Contacts</cfquery>
    <cfset contactid = Val(temp.MaxNum) + 1>
    <!--- ### Create Record ### --->
    <cfquery name="insert" dbtype="ODBC" datasource="#global.dsn#"
    username="#global.dsnusername#" password="#global.dsnpassword#">
    INSERT INTO Contacts (ContactID, Created, Modified, FirstName, LastName,
    Organization, Address1, City, State, Zipcode, Country, Phone1, Email1)
    VALUES
    (#contactid#,#the_datetime#,#the_datetime#,'#the_f irstname#',
    '#the_lastname#','#the_customer#','#the_address#', '#the_city#',
    '#the_state#','#the_zipcode#','US','#the_phone#',' #the_email#')
    </cfquery>
    <cfoutput>#insert.recordcount#..test</cfoutput>..<cfabort>

    srimtm Guest

  6. #5

    Default Re: Unable to Execute Insert Query using cfquery

    First thing is I will need to make some assumptions here, if they are wrong let
    me know


    If the select returns record(s) you set
    <cfset customerid = temp.CustomerID>

    If the select does not return a record, you do another query to get the maxid,
    then you set
    <cfset contactid = Val(temp.MaxNum) + 1>

    In the insert query you use #contactid#

    So one problem will be if contactid never gets set.

    Now the assumptions.
    I assume that the "ContactID" field in the table is an autonumber. If this is
    correct then you can't set it in the insert query.

    I'm also assuming that you have the cfif's and closing cfif's are correct.

    Can you post what your trying to achieve, we may be able to suggest a better
    logical model.

    Ken



    The ScareCrow Guest

  7. #6

    Default Re: Unable to Execute Insert Query using cfquery

    Can you user a build in wizard?
    cfmlgirl Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139