Ask a Question related to Coldfusion Database Access, Design and Development.
-
Pappy17 #1
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
-
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... -
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... -
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... -
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... -
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... -
mxstu #2
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
-
Pappy17 #3
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
-
Abinidi #4
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
-
mxstu #5
Re: Given fieldname could not be found in the table.
Can you post the new code and the complete error message?
mxstu Guest
-
Mountain Lover #6
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
-
mxstu #7
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
-
Pappy17 #8
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
-
jorgepino #9
Re: Given fieldname could not be found in the table.
I would check you ID field
is a autonumber?
jorgepino Guest
-
Pappy17 #10
Re: Given fieldname could not be found in the table.
Yes, jorgepino, it is autonumber.
Thanks.
Pappy17 Guest
-
jorgepino #11
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
-
Pappy17 #12
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
-
mxstu #13
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
-
Pappy17 #14
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
-
mxstu #15
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
-
mxstu #16
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
-
jorgepino #17
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
-
Pappy17 #18
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
-
mxstu #19
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
-
Pappy17 #20
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



Reply With Quote

