发送文本数据库时换行符正在丧失 [英] Line breaks are being lost when sending text to the Database

查看:97
本文介绍了发送文本数据库时换行符正在丧失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因没有被存储在我的数据库从ASP.NET文本框行breakes。

For some reason the line breakes from ASP.NET textboxes are not being stored in my database.

我使用Server.HtmlEn code(txtAbout.Text)采取从文本框中的文本。
这部分作品和文字取出换行。

I am using Server.HtmlEncode(txtAbout.Text) to take the text from the textbox. This part works and text is taken out with line breaks.

但是,当我追寻文字,换行符被这条线后会丢失:

But when I trace the text, the line breaks are lost after this line:

db.AddInParameter(dbCommand, "About", DbType.String, about);
db.ExecuteNonQuery(dbCommand);

在存储过程中varable @about是NTEXT。
在表中对列是NTEXT

In the stored procedure the varable @about is ntext. In the table the column about is ntext

我希望有人可以提供帮助。

I hope someone can help.

推荐答案

你能追查什么价值约就是送它关闭的存储过程前?

Could you trace what the value of "about" is before sending it off to the stored procedure?

我怀疑所发生的事情是,当你输出所存储的结果,您需要将其分配给一个标签。它,而输出的文字:

I suspect what is happening is when you are outputting the stored result, you are assigning it to a label. Rather output it to a literal:

<asp:Literal runat="server" id="litAbout" />

然后,一旦你这样做,然后执行安置。例如:

Then once you have done that, then do the "placement". For example:

litAbout.Text = Server.HtmlEncode(aboutText).Replace(Environment.NewLine, "<br/>");

另外,就是要带code的输出。你几乎总是只能做之前,输出的结果最终转化;该想法是,你不想失去原始输入。

Also, that is where you want to encode the output. You almost always only do the final transformations prior to outputting the result; the thinking is that you don't want to lose that raw input.

这篇关于发送文本数据库时换行符正在丧失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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