简体   繁体   English

使用行号将值从“多行文本”框中保存到SQL Server中

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

I got one multiline textbox call txtDesc. 我有一个多行文本框调用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. 谢谢。

Love the sample text :) 喜欢示例文字:)

How are you saving and loading this to/from SQL ? 如何保存和从SQL加载和加载? If I have a multiline textbox, the .Text property includes the line break character - 如果我有多行文本框,则.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 ? 您可以发布您的加载/保存代码吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM