Link to home
Start Free TrialLog in
Avatar of jacquard
jacquard

asked on

Key Field Problem

Running Cold Fusion 4.0 with MS-Access on a stand-alone test box, I am trying to run a DoEdit but I keep getting an error saying that I have not identified a primary key in the table. I have done this, deleted and re-entered the database in the ODBC datasources and verified it. I still get this error!
Any suggestions?
Avatar of paulkd
paulkd

Hi jacquard,

I've never heard of a DoEdit, but it sounds interesting. Is it an Access 2000 function?
There is no ColdFusion Function called DoEdit what are you trying to do that is not working?

Nathan Stanford
Mr. ColdFusion
ColdFusion Tips Plus
www.nsnd.com
Avatar of jacquard

ASKER

Sorry, what I meant to type was that I am trying to do an edit of some records using CFUPDATE. The "DoEdit" is just a call.

If your table has a primary key, then you must send the primary key field value into the CFUPDATE as well..

For example:

PAGE1.CFM

<FORM ACTION="page2.cfm" METHOD="POST">
      <INPUT TYPE="Hidden" NAME="userid" VALUE="1">
      <INPUT TYPE="Hidden" NAME="password" VALUE="test">
      <INPUT TYPE="Submit">
</FORM>

PAGE2.CFM

<CFUPDATE DATASOURCE="mydatasource" TABLENAME="mytablename" DBTYPE="ODBC" FORMFIELDS="userid, password">

If you don't want to use a primary key, you should be able to get around this limitation by just using CFQUERY with an update statement:

<!--- Update all records --->
<CFQUERY NAME="myquery" DATASOURCE="mydatasource">

UPDATE mytablename
SET password = 'test'

</CFQUERY>

I hope that is on the right track of what you are asking..if not, can you post some sample code?
Hiz!

Jacquard, can you show us the exact error message are you getting. It's also a plus if you can show us the table structure and the cfm code your are getting in trouble.

Thanks,
cfmrulez!
OK...I think I may have stumbled onto the problem but in doing so uncovered another. My original query read:
<CFUPDATE DATASOURCE="training" TABLENAME="RJITF Courses" dbtype="odbc">

<CFQUERY NAME="GetData" DATASOURCE="training">
SELECT *
FROM RJITF Courses
ORDER BY RecordID
</CFQUERY>

I found that Cold Fusion didn't like spaces in the "TABLENAME" field nor did it like brackets, quotes, or anything else.

After renaming the table to "RJITFCourses" I now get the error:
"ODBC Error Code=22005 (Error in assignment)"

In the debug mode it shows the SQL as:
SQL="UPDATE RJITFCourses SET 'DURATION' =?, 'TARGET'=?, 'PLACE'=?, 'COURSENAME'=?, 'CODE'=?, 'REP_CODE'=?, 'COURSEDESC'=?, WHERE 'RecordID'=?"

Any help before I lose more hair?

thanks

ASKER CERTIFIED SOLUTION
Avatar of Dain_Anderson
Dain_Anderson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Although this answer did not resolve the problem, it did put me on the right track to finding the solution myself.

The problem was an error in my code where I included a "hidden" field statement where I shouldn't have.

Many thanks to Dain and everyone else who provided input.

Mike