如何存储使用SSMS SQL Server 2005中多行文字? [英] How to store a multi-line text in sql server 2005 using SSMS?

查看:164
本文介绍了如何存储使用SSMS SQL Server 2005中多行文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个类似的问题,但没有得到满意的答案。我要存储在表款的SQL Server 2005中我试过所有的数据类型(nvarchar的,VARCHAR,文本等),但是当我复制的内容,它只能存储1号线。帮帮我吧。

I got similar questions to this but not get satisfied answers. I want to store paragraph in table in sql server 2005. I tried all data types (nvarchar, varchar, text etc.) but when I copy the content, it store only 1st line. Help me.

我使用SQL Server Management Studio和直接复制粘贴内容到表。而对于检索我用这个code。

I am using Sql Server Management Studio and directly copy paste the content into table. And for retrieving I use this code.

String query2 = String.Format("select data from try where roll=55");
SqlCommand cmd2 = new SqlCommand(query2, conn);
SqlDataReader reader2 = cmd2.ExecuteReader();
if (reader2.Read())
    {
        Label1.Text = reader2.GetValue(0).ToString();

    }

其中'数据'是多行的内容。

where 'data' is multiline content.

推荐答案

我没有使用SQL Server 2008 R2的一个小测试(因此,它可能在2005年会有所不同):

I did a little test using Sql Server 2008-R2 (So it might be different on 2005):

insert into Test1 (Col1) VALUES('THIS
INSERTS

A

Multiline

String')

选择

当,结果看起来像没有换行符,但如果你检查CHAR(10)和char(13) - (CRLF)他们做的字符串中存在...

When selecting, the result DOES look like there are no line-breaks, BUT if you check for char(10) and char(13) - (CRLF) they DO exist in the string...

select col1, REPLACE(REPLACE(col1,CHAR(10), 'X'),CHAR(13), 'Y') as LineBreaks from Test1

结果:

Result:

这篇关于如何存储使用SSMS SQL Server 2005中多行文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆