Sir,
In below code I want to save multiline text in sql database table with line break as it being typed on textarea. The column datatype is ntext.
When I am saving the data to database on button click, the text would saving without line break.
how should I do this?
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("estatesConnectionString").ConnectionString)
Dim cmd As New SqlCommand("insert into textTab(text1) values(@a)", con)
cmd.Parameters.AddWithValue("@a", Replace(remove_bad_words(tContent.Text.Trim), "<br/>", vbCrLf))
con.Open()
cmd.ExecuteNonQuery()
con.Close()
remove_bad_words Method:
Public Function remove_bad_words(ByVal stringword As String) As String
Dim functionReturnValue As String = Nothing
Try
If String.IsNullOrEmpty(stringword) Then
'return functionReturnValue;
Return ""
End If
Dim newChars As String = Nothing
Dim badstuff As String() = {"'", "CREATE", "UPDATE", "SELECT", "UNION", "DROP", ";", _
"--", "INSERT", "DELETE", "TRUNCATE", "XP_", "*", _
"<", ">", "%", "=", "SCRIPT", "ALERT", _
"HAVING", "MASTER..XP_CMDSHELL", "XP_STARTMAIL", "XP_SENDMAIL", "SP_MAKEWEBTASK", "=", _
"~", "!", "@", "#", "$", "%", _
"^", "&", "*", "(", ")", "_", _
"+", "`", "{", "}", "[", "]", _
":", ";", """,""", ",", _
"?", "|", "\", "\", "open()", "sysopen()", _
"system()", "<>", "()", "eval()"}
newChars = stringword
For i As Integer = 0 To badstuff.Length - 1
newChars = newChars.Replace(badstuff(i), "")
Next
Return newChars
Catch ex As Exception
Response.Redirect("~/Error.aspx", True)
End Try
Return functionReturnValue
End Function