Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robert 19 posts 39 karma points
    Mar 19, 2012 @ 23:20
    Robert
    0

    Custom Section Tags

    Hi Everyone,

    Im struggling with getting tags to successfully add to the DB from a custom section I have setup. All the other fields work correctly and I can add and edit successfully.

    My custom section has a form with 4 fields and the code to process the form looks this so far:

            void save_Click(object sender, ImageClickEventArgs e)
            {
                string tag = txtTags.Text;
                string group = "default";
                int nodeId = int.Parse(Request["id"]);
    
                int tagId = Tag.GetTagId(tag, group);
    
                if (tagId == 0)
                {
                    tagId = Tag.AddTag(tag, group);
                }
    
                Tag.AssociateTagToNode(nodeId, tagId);
    
                string updateStatement =
                    @"update codeSnippets set 
                        wrongWord = @wrongWord,
                        correctWord = @correctWord,
                        cause = @cause 
                        where id = @id;";
    
                umbraco.BusinessLogic.Application.SqlHelper.ExecuteNonQuery(
                    updateStatement,
                    umbraco.BusinessLogic.Application.SqlHelper.CreateParameter("@wrongword", txtWrongWord.Text),
                    umbraco.BusinessLogic.Application.SqlHelper.CreateParameter("@correctword", txtCorrectWord.Text),
                    umbraco.BusinessLogic.Application.SqlHelper.CreateParameter("@cause", txtCause.Text),
                    umbraco.BusinessLogic.Application.SqlHelper.CreateParameter("@id", nodeId)
                );
    
            }

    The tag is adding to the cmstags table but I get an error when it tries to create therelationship to the node. 

    The error is:

    Cannot add or update a child row: a foreign key constraint fails (`web211-database`.`cmstagrelationship`, CONSTRAINT `UMBRACONODE_CMSTAGRELATIONSHIP` FOREIGN KEY (`NODEID`) REFERENCES `umbraconode` (`ID`) ON DELETE CASCADE)


    Can anyone give me any suggestiosn as to what is wrong or how to do this?

     

    Thanks
    Robert

  • Robert 19 posts 39 karma points
    Mar 20, 2012 @ 01:22
    Robert
    0

    I think I have discovered the problem. The nodes that are being creating in my custom section are not being added to the NODEID list in the 'mstagrelationship' table. Therefore it fails as it cannot find the ID.

    How do I get around this?

     

    Thanks
    Rob

  • Robert 19 posts 39 karma points
    Mar 20, 2012 @ 17:46
    Robert
    0

    Anyone? Need to figure out how I get my custom section nodes to appear in the cmstagrelationship.NODEID dropdown?

Please Sign in or register to post replies

Write your reply to:

Draft