Error when trying to save...

Last post 09-21-2006, 6:01 AM by AndyFel. 4 replies.
Sort Posts: Previous Next
  •  09-19-2006, 10:06 AM 22823

    Error when trying to save...

    When I try and save text from the editor that is longer than 4000 characters, I receive the following message, "Implicit conversion from data type ntext to varchar is not allowed...". The field that I'm trying to save into has varchar(8000) as the datatype. The stored procedure also has the same datatype.
     
    I've added "MaxHTMLLength=8000" to the editor.
     
    Does the editor convert the text to unicode (2 bytes per character) before it saves it into the database?
  •  09-20-2006, 2:24 PM 22863 in reply to 22823

    Re: Error when trying to save...

    sbarrier,
     
    Please check your DB table setting and store procedure (if you are using it). It has nothing to do with this Rich Text Editor.
     
    >>Does the editor convert the text to unicode (2 bytes per character) before it saves it into the database?
     
    The content extracted from the editor is regular string. CuteEditor will not convert the string into unicode text.
     
    If it doesn't help, please provide your table setting information and store procedure you are using to save the data.
     
     
     
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  09-20-2006, 3:19 PM 22868 in reply to 22863

    Re: Error when trying to save...

    Here is the ASP.NET code:
                sDesc = Editor2.Text
                sDesc = Replace(sDesc, vbCrLf, "")
                If Len(sDesc) = 0 Then
                    sDesc = Chr(0)
                End If
                sDesc = Replace(sDesc, "<ul>", "<ul class='checkboxlist'>")
                sFilename = Replace(Filename.Value, "/", "\")
                If Len(sFilename) = 0 Then
                    sFilename = Chr(0)
                End If
                oConn.Open()
                With oCmd
                    .Parameters.Clear()
                    .Connection = oConn
                    .CommandType = Data.CommandType.StoredProcedure
                    .CommandText = "IatricWeb_update_news"
                    .Parameters.AddWithValue("@Title", Title.Text)
                    .Parameters.AddWithValue("@ShortDescription", Editor1.Text)
                    .Parameters.AddWithValue("@Description", sDesc)
                    .Parameters.AddWithValue("@Link", Link.Text)
                    .Parameters.AddWithValue("@Image", sFilename)
                    .Parameters.AddWithValue("@SubmitDate", NewsDate.Text)
                    If Feature.Checked = True Then
                        .Parameters.AddWithValue("@Feature", 1)
                    Else
                        .Parameters.AddWithValue("@Feature", 0)
                    End If
                    If Inactive.Checked = True Then
                        .Parameters.AddWithValue("@Inactive", 1)
                    Else
                        .Parameters.AddWithValue("@Inactive", 0)
                    End If
                    .Parameters.AddWithValue("@NewsID", NewsID.Value)
                    .ExecuteNonQuery()
                End With 
     
     
    Here is the SP: 
    CREATE PROCEDURE IatricWeb_update_news
    @Title varchar(50), @ShortDescription varchar(275), @Description varchar(8000),
    @Link varchar(250), @Image varchar(250), @SubmitDate datetime,
    @Feature bit, @Inactive bit, @NewsID int
    AS
    Update IatricWeb..TAB_News
    Set Title = @Title,
     ShortDescription = @ShortDescription,
     [Description] = @Description,
     Link = @Link,
     [Image] = @Image,
     [Date] = @SubmitDate,
     Feature = @Feature,
     Inactive = @Inactive
    Where NewsID = @NewsID
     
    I've also verified that the field in the SQL database has a datatype of varchar(8000).
  •  09-20-2006, 3:27 PM 22869 in reply to 22868

    Re: Error when trying to save...

    Can you change sDesc = Editor2.Text to sDesc = "Hello world" and try again?

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  09-21-2006, 6:01 AM 22898 in reply to 22868

    Re: Error when trying to save...

    Hi
     
    Adam is right about this in that its not the editor causing the problem, its the way you are creating the stored proc parameters.
     
    You are using   .Parameters.AddWithValue("@Description", sDesc)
     
    This will try to determine the type and length from the string being passed to it and not the database parameters. You need to explicitly create your parameters
     
        .Parameters.Add("@Description", SqlDbType.VarChar, 8000).Value = sDesc
     
    This also has the advantage that if you forget to limit the sDesc variable to 8000 it wont complain it just truncates the value, plus it will convert the string to the correct type ie. non unicode 8000 length.
     
    Hope this helps
    Andy
View as RSS news feed in XML