vb.net 使用换行符将多行文本框中的值保存到 SQL Server 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20536431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Save the value from Multiline Textbox into SQL Server with line brea
提问by user2412351
I got one multiline textbox call txtDesc. The user can key in multiline value such as :
我有一个多行文本框调用 txtDesc。用户可以键入多行值,例如:
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.
谢谢你。
采纳答案by user2412351
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
回答by sh1rts
Love the sample text :)
喜欢示例文本:)
How are you saving and loading this to/from SQL ? If I have a multiline textbox, the .Textproperty includes the line break character -
您如何将其保存和加载到 SQL 或从 SQL 加载?如果我有一个多行文本框,则该.Text属性包括换行符 -
"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.
我将其保存到 SQL 表中的 NVARCHAR(MAX) 字段中,当我将其加载回文本框时,我得到的换行符与输入的完全相同。
Can you post your your load/save code ?
你能发布你的加载/保存代码吗?

