Save the value from Multiline Textbox into SQL Server with line brea

我是研究僧i 提交于 2019-12-04 05:23:47

问题


I got one multiline textbox call txtDesc. The user can key in multiline value such as :

Hai.
I'm robot.
Please feed me.

I want to save into database with the line break and will display it back later as user key in.

if i save the value as below code, the line break will not save.

dim strDesc as string = txtDesc.text

how to make this happen?

Thank you.


回答1:


Love the sample text :)

How are you saving and loading this to/from SQL ? If I have a multiline textbox, the .Text property includes the line break character -

"Hai.\n\I'm robot.\n\Please feed me."

I save this into an NVARCHAR(MAX) field in a table in SQL, and when I load it back into the textbox, I get the line breaks exactly as it was typed in.

Can you post your your load/save code ?




回答2:


i got the answer :

To save from multiline textbox to database :

  Dim strDesc As String
  strDesc = ReplaceNewLines(txtDesc.Text, True)

To show back from database to multiline textbox :

strDesc = productDetails.ProductDesc.Replace("<br/>", vbCrLf)
txtDesc.Text = strDesc


来源:https://stackoverflow.com/questions/20536431/save-the-value-from-multiline-textbox-into-sql-server-with-line-brea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!