cfwindow-cfgrid-cfgridupdate problem

Hello experts.
I m using cfwindow and cfgrid with cfgridupdate.
If i submit the form without changing any field i have an error:The cfgridupdate tag cannot find the grid named Kategorie.
If i make any change and submit the form I get an error:
 Primary key not found for the Kategorie table.
The table you are attempting to update, Kategorie does not have a primary key, which is a field or set of fields that uniquely identify each record..Any help?
(i'm using cf8 and mysql)

<a href="#" onclick="ColdFusion.navigate('includes/body.cfm?action=categories', 'getfilespage'); ColdFusion.Window.show('getfilespage');">Categories</a><br>



<cfwindow center="true"
          name="getfilespage"
          minHeight="150" 
          minWidth="150" 
          title="Body" 
          initshow="false"
          modal="true"/>


the body.cfm
<cfif url.action EQ 'categories'>
<cfif IsDefined("form.gridEntered") is True>
   <cfgridupdate grid = "Kategorie" dataSource = "#request.dsn#" Keyonly="true" tableName = "Kategorie">
 </cfif>

<cfquery name="q_Kategorie" datasource="#request.dsn#">
SELECT Kat_Text,Kat_ID,langid,mobiles_sub_id
FROM <!---dbo.--->Kategorie
ORDER BY Kat_ID ASC 
</cfquery>
 <cfform>
   <cfgrid name="Kategorie" format="html" query="q_Kategorie" pagesize="7" insert = "Yes"  delete = "Yes" sort="yes"
 selectmode="edit">
      <cfgridcolumn name="Kat_ID" header="ID" width="30"/>
      <cfgridcolumn name="Kat_Text" header="Text" width="120"/>
      <cfgridcolumn name="mobiles_sub_id" header="Mobile" width="40"/>
      <cfgridcolumn name="LangID" header="LangID" width="40"/>
   </cfgrid>
   <cfinput type="submit" name="gridEntered">

</cfform>
</cfif>

Open in new window

LVL 2
PanosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
>>> If i submit the form without changing any field i have an error
>>> <cfif IsDefined("form.gridEntered") is True>

    Dump the FORM scope just before that line. What are the results?

>>> Primary key not found for the Kategorie table

    I assume "Kat_ID" is the primary key in your table?  It sounds like you didn't
    define that column as the PRIMARY KEY when you created the table in MySQL
    http://dev.mysql.com/doc/refman/5.1/en/create-table.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PanosAuthor Commented:
Hi agx.
I dump the form but i get the coldfusion errormessage.
using cfdebug i get this error:error:http: Error retrieving markup for element getfilespage_body : Internal Server Error

0
_agx_Commented:
No, I mean just dump the scope normally, using CFDUMP

<cfdump var="#FORM#">
<cfif IsDefined("form.gridEntered") is True>
0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

PanosAuthor Commented:
I did exactly this.
when the cfwincow opens it shows struct [empty] and when i hit the submit button i get the error:The cfgridupdate tag cannot find the grid named Kategorie.
0
_agx_Commented:
One of us is misunderstanding something ;-)  

In order to see what values are sent when the form is submitted, you need to place cfdump code BEFORE the cfif/cfgridupdate code.  Otherwise, an error happens and the results are never shown.

<cfif url.action EQ 'categories'>
    <CFDUMP VAR="#FORM#">             <!--- MUST be placed before the grid update --->

    <cfif IsDefined("form.gridEntered") is True>
           <cfgridupdate grid = "Kategorie" dataSource = "#request.dsn#" Keyonly="true" tableName = "Kategorie">
     </cfif>

</cfif>


0
PanosAuthor Commented:
Here is my code:
<cfif url.action EQ 'categories'>
<cfdump var="#FORM#">
  <cfif IsDefined("form.gridEntered") is True>
   <cfgridupdate grid = "Kategorie" dataSource = "#request.dsn#" Keyonly="true" tableName = "Kategorie">
  </cfif>
   <cfquery name="q_Kategorie" datasource="#request.dsn#">
   SELECT Kat_Text,Kat_ID,langid,mobiles_sub_id
   FROM <!---dbo.--->Kategorie
   ORDER BY Kat_ID ASC
   </cfquery>
  <cfform>
   <cfgrid name="Kategorie" format="html" query="q_Kategorie" pagesize="7" insert = "Yes"  delete = "Yes" sort="yes"
    rowheaderbold="yes" colHeaderBold = "Yes"  selectmode="edit" pictureBar="yes" hspace="0" vspace="0" autowidth="yes">
      <cfgridcolumn name="Kat_ID" header="ID" width="30"/>
      <cfgridcolumn name="Kat_Text" header="Text" width="120"/>
      <cfgridcolumn name="mobiles_sub_id" header="Mobile" width="40"/>
      <cfgridcolumn name="LangID" header="LangID" width="40"/>
   </cfgrid>
   <cfinput type="submit" name="gridEntered">
  </cfform>
</cfif>
0
PanosAuthor Commented:
The other mistery i have is that when i add in the query the column with the primary key(table_id)
i get the error:[Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'table_id'.
0
PanosAuthor Commented:
part of mysql table-settings
screen.gif
0
_agx_Commented:
>> Here is my code:

   Oh, I misunderstood then.  You're saying when you do that the FORM is totally empty?
   Try the exact same code, but without the <cfwindow>.  I'm wondering if cfwindow is messing
   things up.  



0
PanosAuthor Commented:
agx i get the same errors.
Maybe i did something wrong in the mysql table.
0
PanosAuthor Commented:
when imake a change and submit the form:
 Primary key not found for the Kategorie table.
The table you are attempting to update, Kategorie does not have a primary key, which is a field or set of fields that uniquely identify each record.
0
PanosAuthor Commented:
Here is  my new error:
 Primary key(s) table_id not found.
The cfgridupdate tag cannot update or delete the row because it cannot find the primary key(s) table_id in the cfgrid form fields for table Kategorie in datasource....
0
PanosAuthor Commented:
Agx.
Finally a part is working.I add the table_id in the cfgrid but i need it as a hidden field.
<cfform>
   <cfgrid name="Kategorie" format="html" query="q_Kategorie" pagesize="7" insert = "Yes"  delete = "Yes" sort="yes"
    rowheaderbold="yes" colHeaderBold = "Yes"  selectmode="edit" pictureBar="yes" hspace="0" vspace="0" autowidth="yes">
      <cfgridcolumn name="Kat_ID" header="ID" width="30"/>
      <cfgridcolumn name="Kat_Text" header="Text" width="120"/>
      <cfgridcolumn name="mobiles_sub_id" header="Mobile" width="40"/>
      <cfgridcolumn name="LangID" header="LangID" width="40"/>
      <cfgridcolumn name="table_id" header="Table_id" width="40"/>
   </cfgrid>
   <cfinput type="submit" name="gridEntered_kat">
  </cfform>

Now if i make changes and submit the form i have no errors.
If i submit the form without making a change i get the error:
The cfgridupdate tag cannot find the grid named Kategorie.
0
_agx_Commented:
Ok, but is the "table_id" actually defined as the PRIMARY KEY in your table?  If not, that sounds like the problem.  Can script out the mySQL table and post the definition? ie  the CREATE TABLE ...(  statement.
0
_agx_Commented:
Sorry, our posts overlapped. Disregard my last response.
0
PanosAuthor Commented:
CREATE TABLE `kategorie` (
  `table_id` int(11) NOT NULL AUTO_INCREMENT,
  `Kat_ID` int(11) DEFAULT '0',
  `Kat_Text` varchar(50) DEFAULT '',
  `LangID` int(11) DEFAULT '0',
  `Mobiles_sub_ID` int(11) DEFAULT '0',
  PRIMARY KEY (`table_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=89 DEFAULT CHARSET=utf8
0
_agx_Commented:
>> Finally a part is working.I add the table_id in the cfgrid but i need it as a hidden field.

Now that the basic code is functioning, does it work once you put the cfwindow back in?
0
PanosAuthor Commented:
agx i'm back it was too late for me on my last comment.

there is a misfunction using cfwindow It is not updating the correct row.
0
PanosAuthor Commented:
Disregard my last post.
It is the first time i use cfgrid and unfortunately i'm using it in a wrong way.I did  wrong updated  row because i was selecting before submitting another row to deselect the altered row field.Now i'm clicking on the white space and have no mistaces.The only error that remains is if i have not make any change.
0
PanosAuthor Commented:
agx.
Finally i did solve my problem using cfgridaction instead of cfgridupdate.
and for a more complex example i followed the tutorial on this page:http://www.coldfusion-ria.com/Blog/index.cfm/2009/1/21/ColdFusion-8-cfgrid-adding-Add-and-Delete-Record-Functionality where i did add the edit function.
I post a working code below for the first example:
<cfquery name="q_Geschlecht" datasource="#request.dsn#">
    SELECT geschlecht_text ,geschlecht_ID,langid
    FROM t_geschlecht
    </cfquery>
   <cfform>
    <cfgrid name="Geschlecht" format="html" pagesize="30"   delete = "Yes" sort="yes" 
    rowheaderbold="yes" colHeaderBold = "Yes"    pictureBar="yes" hspace="0" vspace="0"  bind="cfc:cfc.geschlecht.getGeschlecht({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})" selectmode="edit" onchange= "cfc:cfc.geschlecht.updateGeschlecht({cfGridAction},{cfgridrow},{cfgridchanged})">
      <cfgridcolumn name="geschlecht_ID" header="ID" width="30"/>
      <cfgridcolumn name="geschlecht_text" header="Text" width="120"/>
      <cfgridcolumn name="LangID" header="LangID" width="40"/>
      <cfgridcolumn name="table_id" header="Table_id"  select="no"/>
    </cfgrid>
  </cfform>

the cfc:
<cffunction name="getgeschlecht" access="remote">
      <cfargument name="page" required="yes">
      <cfargument name="pageSize" required="yes">
      <cfargument name="gridsortcolumn" required="yes">
      <cfargument name="gridsortdirection" required="yes">
    <cfquery name="q_geschlecht" datasource="#request.dsn#">
    SELECT geschlecht_text ,geschlecht_ID,langid,table_id
    FROM <!---dbo.--->t_geschlecht
    <cfif gridsortcolumn neq ''>
      order by #gridsortcolumn# #gridsortdirection#
     </cfif>
    </cfquery>
   <cfreturn queryconvertforgrid(q_geschlecht,page,pagesize)/>
</cffunction>
<cffunction name="updategeschlecht" access="remote">
      <cfargument name="gridaction" type="string" required="yes">
      <cfargument name="gridrow" type="struct" required="yes">
      <cfargument name="gridchanged" type="struct" required="yes">
      <cfset var colname = "">
      <cfset var value = "">
 <cfswitch expression="#arguments.gridaction#">
     <!--- update --->
   <cfcase value="U">
    <cfset colname = StructKeyList(arguments.gridchanged)>
    <cfset value = arguments.gridchanged[colname]>

      <cfquery datasource="#request.dsn#">
        UPDATE t_geschlecht
        SET #colname# = '#value#'
        WHERE table_id = <cfqueryparam value="#arguments.gridrow.table_id#" cfsqltype="cf_sql_integer">
       </cfquery>
     </cfcase>
     <!--- delete --->
      <cfcase value="D">
       <cfquery datasource="#request.dsn#">
       DELETE FROM t_geschlecht
       where table_id = <cfqueryparam value="#arguments.gridrow.table_id#" cfsqltype="cf_sql_integer">
       </cfquery>
      </cfcase>
     </cfswitch>
</cffunction>

Open in new window

0
PanosAuthor Commented:
Thank you
regards
panos
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.