Copied to clipboard

Flag this post as spam?

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


  • Hugh 30 posts 64 karma points
    Feb 05, 2014 @ 19:13
    Hugh
    0

    String or binary data would be truncated. The statement has been terminated.

    Hi all

    I am using Umbraco 7.0.1

    I have cerated a site that is a listing of businesses.  A user can login and create their business, as well as edit their business.

    I have created a ASP.Net user control to allow the users to create and edit their businesses.  I have numerous fields for them to fill out, one in particulare is called Body Text and is of type RichText Box (or Nvarchar) according to the cmsDataType table.

    I can create Businesses (nodes) fine within the CMS itself. Once a business has been created, i can edit it fine without any worries.  The length of theBody Text field (wich i have a multiline text box for) when editing does not seem to matter.

    My issue is creating the new business node. It seems that when creating a new business using my control, if the body text field has a multimple of characters in it, i get the "String or binary data would be truncated. The statement has been terminated." error when saving.   I am using TinyMCE over my multine text box too.

    Here is my code to create:

     Try

                If IsNumeric(txtprice.Text) Then

                    Dim contService As umbraco.Core.Services.ContentService = New umbraco.Core.Services.ContentService                

                    Dim businessListing = contService.CreateContent(pageHeading.Text, 1067, "Business", 0)

                    businessListing.SetValue("pageHeading", pageHeading.Text)

                    businessListing.SetValue("bodyText", txtbodytext.Text)

                    businessListing.SetValue("salePrice", txtprice.Text)

                    businessListing.SetValue("propertyReference", txtreference.Text)

                    businessListing.SetValue("suburb", txtsuburb.Text)

                    businessListing.SetValue("state", ddlstate.SelectedValue)

                    businessListing.SetValue("postCode", txtpostcode.Text)

                    businessListing.SetValue("brokerEmail", txtbodytext.Text)

                    businessListing.SetValue("brokerPhone", txtphone.Text)

                    businessListing.SetValue("pageTitle", pageHeading.Text)

                    businessListing.SetValue("photos", lblhidden.Value.TrimEnd(","))

                    lblerror.Text = lblhidden.Value.TrimEnd(",")

                    Dim m As umbraco.cms.businesslogic.member.Member = umbraco.cms.businesslogic.member.Member.GetCurrentMember()

                    businessListing.SetValue("broker", m.Id)

                    If chkFeatured.Checked Then

                        businessListing.SetValue("isFeatured", 1)

                    Else

                        businessListing.SetValue("isFeatured", 0)

                    End If

                    Dim catString = ""

                    For Each x As ListItem In lstselected.Items

                        catString += x.Value & ","

                    Next

                    catString = catString.TrimEnd(",")

                    businessListing.SetValue("cats", catString)

                    contService.SaveAndPublishWithStatus(businessListing, 0)

                    pnlsuc.Visible = True

                    pnlform.Visible = False

                Else

                    lblerror.Text = "Please just enter a price value in numeric symbols only"

                End If           

            Catch ex As Exception

                lblerror.Text = ex.Message

            End Try

    Something else strange, is if i create the business and leave the body text empty, i can then edit the business and add as much text as i want into the bodytext with out issue.

    There seems to be somehting wrong with my Body Text field when creating. 

  • Hugh 30 posts 64 karma points
    Feb 06, 2014 @ 09:58
    Hugh
    0

    Any help out there with this?  Anyone else had an issue using the API and the datatype Rich Text?

  • Hugh 30 posts 64 karma points
    Feb 06, 2014 @ 10:42
    Hugh
    0

    I have now fixed this issue.  Please disregards

    Hugh

  • Tom 120 posts 448 karma points
    Mar 31, 2014 @ 21:10
    Tom
    0

    And what did you do?

  • Emiel 31 posts 124 karma points
    Mar 13, 2017 @ 12:54
    Emiel
    2

    enter image description here

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 13, 2017 @ 14:17
    Michael Latouche
    0

    Well,

    I don't know if this can help you, but this error occurs when you want to save a text that is longer than the max allowed length of your DB field.

    Looking at the original code posted here, at some point the following occurs:

     businessListing.SetValue("brokerEmail", txtbodytext.Text)
    

    So basically, it appears as if Hugh was trying to save his multiline body text of probably several hundreds characters into an email field of maybe 50? 100? characters, which caused the error.

    In other words, the error did not raise because the body text was too long but because the "broker email" text was too long.

    This would also explain why it was working when leaving the body text empty upon creation: at that moment the "broker email" would also be empty and everything could be saved without error.

    Updating the body text afterwards was probably calling another piece of code where that error was not present.

    So, if you are facing similar issues, it is probably due to text length you are trying to save in the DB...

    And otherwise, maybe you can post some extra info :-)

    Hope this helps.

    Cheers,

    Michael.

Please Sign in or register to post replies

Write your reply to:

Draft