简体   繁体   English

从SQL-Server 2008访问数据库字段到asp.net时出现空白问题

[英]White-space issue while accessing the database field from SQL-Server 2008 into asp.net

I am trying to retrieve one of the database field from sql server 2008 with the following code,In the database the data field is named as OBGST & GYNAECOLOGY which has a ampersand in it. 我正在尝试使用以下代码从sql server 2008检索其中一个数据库字段。在数据库中,数据字段被命名为OBGST & GYNAECOLOGY其中包含一个ampersand Now when i am retrieving in asp.net only the first text before ampersand is been displayed as OBGST ,but the actual result should be OBGST & GYNAECOLOGY . 现在,当我在asp.net中检索时,仅在&符号显示为OBGST之前的第一个文本,但实际结果应该是OBGST & GYNAECOLOGY

I have tried the following code but still didn't get rid of this issue. 我尝试了以下代码,但仍然没有摆脱这个问题。

 literal.Text = "<script>window.open('UploadFiles.aspx?dept="+deptname+"&hosno=" + hosno + "&visitno=" + visitno + "','_blank')</script>";

 txtdept.Text = Request.QueryString["dept"].ToString().Replace("%20&%20", "&");

The problem is not the whitespace, but the ampersand. 问题不是空白,而是&符号。 URLEncode it: %26 , in your literal.Text . URLEncode it: %26 ,在你的literal.Text

You can use Reqex to remove extra space 您可以使用Reqex删除额外的空间

Regex.Replace(YOURTEXT, @"\\s+", "") Regex.Replace(YOURTEXT,@“\\ s +”,“”)

This will remove any space within text. 这将删除文本中的任何空格。

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

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