This is a migrated thread and some comments may be shown as answers.

Formatting long text for SQL Server

1 Answer 93 Views
Editor
This is a migrated thread and some comments may be shown as answers.
sbowman
Top achievements
Rank 1
sbowman asked on 08 Nov 2008, 07:42 PM
I have a page with 2 RadEditor controls on it and I am having problems formatting the text to save into a SQL DB. Here is my code:

Protected

Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click  

 

Dim Title, Abstract, Comments As String  

 

Dim Display As Integer  

 

Dim NewsDate As Date

 

Title =

Me.rtxtTitle.Text

 

 

 Abstract =

Me.redAbstract.Text

 

 

 

Dim strAbstract = Abstract.Substring(0, Abstract.Length - 1)

 

 

 Comments =

Me.redComments.Text

 

 

 

Dim strComments = Comments.Substring(0, Comments.Length - 1)

 

 

 NewsDate =

Me.rdtpNews.DbSelectedDate

 

 

 

If Me.chkDisplayYN.Checked = True Then

 

 

 

Display = 1

 

 

Else

 

 

 

Display = 0 

 

 

End If  

 

'Populate the datatable  

 

Dim sConnString As String = ConfigurationManager.ConnectionStrings("PU89").ConnectionString  

 

Dim objConnection As New SqlClient.SqlConnection(sConnString)  

 

Dim strSQL As String = "INSERT INTO tblNews (Title,Display,BDate,Abstract,Comments)" & _  

 

" VALUES ('" & Title & "', '" & Display & "', '" & NewsDate & "', '" & strAbstract & "', '" & strComments & "');"  

 

Dim dbComm As New SqlClient.SqlCommand(strSQL, objConnection)  

 

Dim iID As Integer  

 

Try 

 

objConnection.Open()

iID = dbComm.ExecuteScalar()

 

Catch ex As Exception  

 

 

Response.Write(ex.Message)

Response.End() 

 

 

Finally  

 

If objConnection.State = ConnectionState.Open Then 

 

objConnection.Close() 

End If  

 

End Try  

 

End Sub

This method works for short blocks of text with no special characters. When I try to enter the complete text (copied from a webpage and pasted into the RadEditor) I get syntax errors:

"Incorrect syntax near 's'. Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon."

Thanks,
Shelley

 

 

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 11 Nov 2008, 05:23 PM
Hi Shelley,

You can think of RadEditor as an enhanced standard Asp:TextBox control and the way the editor has to be bound to a database is similar to this of a standard <asp:TextBox>.

My suggestion is to implement your scenario by replacing RadEditor with a standard Asp:TextBox control. You need to replace the Content property of RadEditor with the Text property of the TextBox control. After that test your scenario and see whether you will experience the same problem with the TextBoxes controls.

Kind regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
sbowman
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or