Given fieldname could not be found in the table.

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

  1. #1

    Default Given fieldname could not be found in the table.

    Another newbie question here. I am trying to update one table ("Table A") and
    insert into another table ("Table B"):

    <cfquery DATASOURCE="tech support survey">
    UPDATE Table A
    SET DateRecd=#Now()#
    WHERE AdminID = #AdminID#
    </cfquery>
    <cfinsert datasource="tech support survey" tablename="Table B">

    When I try to do this, I get an error saying that AdminID cannot be found in
    Table B. Admin ID has nothing to do with Table B.

    What am I doing wrong?

    Thanks!

    Pappy17 Guest

  2. Similar Questions and Discussions

    1. No records found for MySQL Table
      Hello, We have a MySQL table that we had been using PHP to query, but now we want to query the table using CF 5.0 on a windows 2000 server. The...
    2. RS(fieldname) error when using column alias.
      Could someone tell me why I cannot seem to reference a field in a record set which I have given an alias to. I have given the field c.firstname an...
    3. dbase: how to get fieldNAME ofa table
      Hello, below you will find a simple script that reads out info of a dbase It reads out all the records and every field of the record. For my...
    4. Another Dumbass Question: Table not found
      Sadly, I am learning this using Access, no cracks please, its certainly not my preference: I am attempting to connect to the database using...
    5. Help with inserting values from information not found in another table
      I have a tmp_phone that I am comparing to table_phonelistings using the phone field. I then want to insert the values (ac,phone) from the...
  3. #2

    Default Re: Given fieldname could not be found in the table.

    This is just guessing... but it may be a scope problem. I assume #AdminID# is
    a form field variable? Since you do not specify the fields to insert in your
    CFINSERT statement, the tag may just be grabbing all of the form field names
    and attempting to insert them all into your table. Since you say that AdminID
    does not exist in Table B, CFINSERT throws an error.

    Try specifying the names of the columns to insert by using the "formFields"
    attribute of CFINSERT.

    Also, you should scope your variables, for example:

    #form.myID#
    #url.myParam#
    etc....



    mxstu Guest

  4. #3

    Default Re: Given fieldname could not be found in the table.

    Thanks, mxstu. Now I'm getting a "Syntax error in INSERT INTO statement" message. I haven't tried putting "form." in front of the variables yet.
    Pappy17 Guest

  5. #4

    Default Re: Given fieldname could not be found in the table.

    <cfquery DATASOURCE="tech support survey">
    UPDATE Table A
    SET DateRecd=#Now()#
    WHERE (AdminID = #AdminID#)
    </cfquery>

    Surround the WHERE in parenthesis...
    Try that
    Abinidi Guest

  6. #5

    Default Re: Given fieldname could not be found in the table.

    Can you post the new code and the complete error message?
    mxstu Guest

  7. #6

    Default Re: Given fieldname could not be found in the table.

    Historically, it was a bad idea to have spaces in table/field names and
    they will cause errors. You can get around this by surrounding the table
    name in quotes 'Table A' or renaming it.
    HTH


    --
    Tim Carley
    [url]www.recfusion.com[/url]
    [email]info@NOSPAMINGrecfusion.com[/email]
    Mountain Lover Guest

  8. #7

    Default Re: Given fieldname could not be found in the table.

    Originally posted by: Newsgroup User
    Historically, it was a bad idea to have spaces in table/field names and
    they will cause errors. You can get around this by surrounding the table
    name in quotes 'Table A' or renaming it.


    Agreed. IMO spaces in table names are not a good idea. I assumed (perhaps
    incorrectly) that "Table A" was not the real table name ... or more accurately
    that the real table name did not have a space in it ;-)


    mxstu Guest

  9. #8

    Default Re: Given fieldname could not be found in the table.

    Thanks to everyone for their help!

    mxstu, your assumption was correct. I was using "Table A" and "Table B" for
    the sake of clarity.

    Here is my code:
    <cfquery DATASOURCE="tech support survey">
    UPDATE IMSAdmin
    SET DateRecd=#Now()#
    WHERE AdminID = #AdminID#
    </cfquery>
    <cfinsert
    DATASOURCE="tech support survey"
    tablename="IMSSurvey"
    formfields="ID, First, Last, CompName, Street1, City, State, Zip, PhoneNum,
    CustID, Email, Product, PMgr, PS1, PS2, PMQuest1, PMQuest2, PMQuest3, PMQuest4,
    PMQuest5, PMComment, PSQuest1, PSQuest2, PSQuest3, PSQuest4, PSQuest5,
    PSComment, GIQuest1, GIQuest2, GIQuest3, GIQuest4, GIComment, BeAReference,
    ReferUs, AddlComment, Date, Time, RName, RecipEmail, DateSent"
    >
    The error message I get now is:
    Error Executing Database Query.
    [MERANT][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access
    Driver] You tried to assign the Null value to a variable that is not a Variant
    data type.

    The Error Occurred in D:\Inetpub\isi-info.com\Surveys\IMS\thanks.cfm: line 15

    13 : tablename="IMSSurvey"
    14 : formfields="ID, First, Last, CompName, Street1, City, State, Zip,
    PhoneNum, CustID, Email, Product, PMgr, PS1, PS2, PMQuest1, PMQuest2, PMQuest3,
    PMQuest4, PMQuest5, PMComment, PSQuest1, PSQuest2, PSQuest3, PSQuest4,
    PSQuest5, PSComment, GIQuest1, GIQuest2, GIQuest3, GIQuest4, GIComment,
    BeAReference, ReferUs, AddlComment, Date, Time, RName, RecipEmail, DateSent"
    15 : >
    16 : <cfquery NAME="thanks" DATASOURCE="tech support survey" maxrows="1">
    17 : SELECT First, Last, RName

    Pappy17 Guest

  10. #9

    Default Re: Given fieldname could not be found in the table.

    I would check you ID field
    is a autonumber?
    jorgepino Guest

  11. #10

    Default Re: Given fieldname could not be found in the table.

    Yes, jorgepino, it is autonumber.

    Thanks.
    Pappy17 Guest

  12. #11

    Default Re: Given fieldname could not be found in the table.

    if you trying to add ID number to a field with auto number you may get the error
    take the ID out to the list and see what happend or turn the autonumbering off


    jorgepino Guest

  13. #12

    Default Re: Given fieldname could not be found in the table.

    jorgepino,

    I left the ID in, and turned autonumbering off. I now get an "Index or primary key cannot contain a Null value. " error. Should I do something in Access?

    Thanks.
    Pappy17 Guest

  14. #13

    Default Re: Given fieldname could not be found in the table.

    Pappy17,

    Leave the [ID] number out as jorgepino mentioned. You don't want to insert the unique record ID, you want it to be be automatically created by Access when you insert the other fields.

    mxstu Guest

  15. #14

    Default Re: Given fieldname could not be found in the table.

    Thanks, mxstu.

    I took out the ID number from <cfinsert> , and now I get this ever popular
    error:

    Error Executing Database Query.
    [MERANT][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access
    Driver] Too few parameters. Expected 1.

    The Error Occurred in D:\Inetpub\isi-info.com\Surveys\IMS\thanks.cfm: line 34

    32 : FROM IMSSurvey
    33 : ORDER BY ID DESC
    34 : </cfquery>
    35 : <cfmail
    36 : QUERY="Thanks2"

    --------------------------------------------------------------------------------

    SQL SELECT ID, First, Last, CompName, Street1, City, State, Zip, PhoneNum,
    Email, Product, Date, BeAReference, CustID, ReferUs, PMgr, PS1, PS2, PMQuest1,
    PMQuest2, PMQuest3, PMQuest4, PMQuest5, PMComment, PSQuest1, PSQuest2,
    PSQuest3, PSQuest4, PSQuest5, PSComment, GIQuest1, GIQuest2, GIQuest3,
    GIQuest4, GIComment, AddlComment, RName FROM IMSSurvey ORDER BY ID DESC
    DATASOURCE tech support survey
    VENDORERRORCODE -3010
    SQLSTATE 07002

    Here's the code (lines 21-34):
    <cfquery NAME="thanks2" DATASOURCE="tech support survey" maxrows="1">
    SELECT ID, First, Last, CompName, Street1, City, State, Zip, PhoneNum, Email,
    Product, Date, BeAReference, CustID, ReferUs, PMgr, PS1, PS2,

    PMQuest1, PMQuest2, PMQuest3, PMQuest4, PMQuest5, PMComment,

    PSQuest1, PSQuest2, PSQuest3, PSQuest4, PSQuest5, PSComment,

    GIQuest1, GIQuest2, GIQuest3, GIQuest4, GIComment,

    AddlComment, RName

    FROM IMSSurvey
    ORDER BY ID DESC
    </cfquery>

    Thanks everyone again for all your help.

    Pappy17 Guest

  16. #15

    Default Re: Given fieldname could not be found in the table.

    So this error isn't from the CFINSERT statement, it's from the next query
    containing a SELECT statement? Just a guess, but I would think it's caused by
    the column named "Date". Date is a reserved word. Try changing it to
    something else .. ex. myDateColumn.



    mxstu Guest

  17. #16

    Default Re: Given fieldname could not be found in the table.

    Hmm .. once you get the "too few parameters ..." error fixed... are you depending on that SELECT statement to give you the information just inserted by the CFINSERT statement?
    mxstu Guest

  18. #17

    Default Re: Given fieldname could not be found in the table.

    poppy17
    I would recomend for you to use the
    <CFQUERY DATASOURCE="indium">
    INSERT INTO dbo.tEmployee (First, Last, CompName, ... )
    SELECT '#Form.First#', '#Form.Last#','#form.CompName#' .....
    </CFQUERY>
    also you need to change the Date and time field they are reserved word and
    will couse problems


    jorgepino Guest

  19. #18

    Default Re: Given fieldname could not be found in the table.

    mxstu and jorgepino,

    Thanks so much for all your help. I changed the name of the Date and Time
    columns, and that did the trick!

    mxstu, yes, I am depending the SELECT statement to provide information just
    inserted by the CFINSERT statement.

    Pappy17 Guest

  20. #19

    Default Re: Given fieldname could not be found in the table.

    Originally posted by: Pappy17
    mxstu, yes, I am depending the SELECT statement to provide information just
    inserted by the CFINSERT statement.

    You may have a problem with that. The current code assumes that no other
    records will be inserted into TableB in between the CFINSERT and the SELECT
    statement, which is not true. Another record can be inserted within that
    window, and if this happens your select statement will return the wrong ID.

    1) You should wrap all of the related queries within a CFTRANSACTION. This
    will ensure that if one query fails, all of the queries will fail as a single
    unit.

    2) As jorgepino suggested, you can use a CFQUERY instead of CFINSERT. If you
    use CFQUERY, you can use then SELECT @@IDENTITY to retrieve the correct ID of
    the record just inserted.

    Using the two steps above will help ensure that you retrieve the information
    for the correct record ID.



    mxstu Guest

  21. #20

    Default Re: Given fieldname could not be found in the table.

    Thanks again, mxstu. I'll make those changes.

    I'm not a programmer, just a technical writer. I have enough problems with English let alone ColdFusion!
    Pappy17 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