开发者

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. 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.

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?


First, you should see if the CR/LFs are in the database.

In the SQL Server Management Studio, Query window, enter

SELECT [ColumnName] FROM [TableName]

where [ColumnName] and [TableName] describe where the data is stored.

From the Query menu, select Results To -> Results to Text (ctrl-T), and then run. You should see multi-line output.


Not sure what you'd look for in the database.

But you might try xml:space="preserve" in your wpf textblock.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜