如何将带有多行分隔符的文本存储到数据库中?
我有一些文本,
例如
line one \r\n
line two \r\n
line threee.
在我的数据库中,我有一列定义为类型 text
,然后我使用实体框架来映射该列,实体框架生成的代码是类型 string
我可以成功将该文本保存到数据库的列中。但是,从 Management Studio 中,我看不到那些行分隔符,当我复制值并粘贴到记事本时,它们已成为一行文本。
有人知道问题是什么吗?
谢谢。
I have some text,
e.g
line one \r\n
line two \r\n
line threee.
In my database, I have a column define as type text
, then I use Entity Framework to map that column, the code generate by Entity Framework is type string
I can successfully save that text into the column in the database. However, from Management Studio, I couldn't see those line separators, when I do copy value, and paste to notepad, they have become one line of text.
Anyone know what the problem is?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题只是 Management Studio 不支持所有字符。当您复制值时,它会删除换行符。
如果将结果从网格更改为文本(查询 -> 结果到 -> 结果到文本,或 ctrl+T),并选择值,您将看到文本以单独的行形式出现。
The problem is simply that Management Studio doesn't support all characters. It removes the line breaks when you copy the value.
If you change the result from grid to text (Query -> Results To -> Results to text, or ctrl+T), and select the value, you will see that the text comes out as separate lines.
在存储文本数据时,您应该坚持使用 NVarchar(原因之一是它支持更多字符)。
以下是 msdn 的摘录:
“ntext、text 和 image 数据类型将在 Microsoft SQL Server 的未来版本中删除。避免在新的开发工作中使用这些数据类型,并计划修改当前使用它们的应用程序。请改用 nvarchar(max)、varchar(max) 和 varbinary(max)”。
详细信息:
You should stick to NVarchar when it comes to store text data (one of the reason is that it supports more characters).
Heres an extract from msdn:
"ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead".
More info:
这很可能是管理工作室的问题。尝试从 C# 查询数据库并打印字段的值。您将立即看到 CRLF 是否存在。
This could quite simply be a problem with the management studio. Try querying the database from C# and printing the field's value. You will see immediately if the CRLFs are there.