简体   繁体   English

如何在将数据从 web 服务移动到 Sql Server 2005 时保留回车?

[英]How do I retain carriage returns while moving data from a web service into Sql Server 2005?

My carriage returns are lost when inserted into Sql Server 2005 as an NVarChar parameter coming from a web service.当作为来自 web 服务的 NVarChar 参数插入 Sql Server 2005 时,我的回车丢失了。 I know the carriage returns exist in the web service fields because when I bind the same data to a WPF ComboBox I see returns occurring in the proper locations.我知道 web 服务字段中存在回车,因为当我将相同的数据绑定到 WPF ComboBox 时,我看到回车出现在正确的位置。

The code looks something like this:代码看起来像这样:

string insertSQL = "INSERT INTO myTable (FieldWithCrLf,...) VALUES (@FieldWithCrLf,...)";

dbConn.Open();

using (SqlCommand cmd = new SqlCommand(@insertSQL, dbConn))
    {
        cmd.Parameters.Add("@FieldWithCrLf", SqlDbType.NVarChar, 4000);
        ...
    }

foreach (WebServiceRecord rec in allDataFromWebService)
    {
        cmd.Parameters["@FieldWithCrLfr"].Value = rec.FieldWithCrLfFromWebService;
        ...
        cmd.ExecuteNonQuery();
    }

How can I retain the carriage return / line feeds so they are stored in my Sql Server fields?如何保留回车/换行符,以便将它们存储在我的 Sql 服务器字段中?

First, you should see if the CR/LFs are in the database.首先,您应该查看 CR/LF 是否在数据库中。

In the SQL Server Management Studio, Query window, enter在SQL Server Management Studio中,查询window,输入

SELECT [ColumnName] FROM [TableName]

where [ColumnName] and [TableName] describe where the data is stored.其中 [ColumnName] 和 [TableName] 描述了数据的存储位置。

From the Query menu, select Results To -> Results to Text (ctrl-T), and then run.从 Query 菜单中,select Results To -> Results to Text (ctrl-T),然后运行。 You should see multi-line output.您应该看到多行 output。

Not sure what you'd look for in the database.不确定您要在数据库中查找什么。

But you might try xml:space="preserve" in your wpf textblock.但是您可以在 wpf 文本块中尝试 xml:space="preserve"。

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

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