2009-04-09 19 views
1

我有一个SQL数据源,我有一个非常长的SQL字符串。我想把换行符放入我的sql中,但Visual Studio似乎不喜欢换行符。我将如何放置换行符?如何将换行符添加到ASP.NET控件声明中的属性?

<asp:SqlDataSource ID="SqlDataSource1" runat="server"   
     ProviderName="System.Data.SqlClient" 
     SelectCommand="select aci.ACIOI, aci.AccountNum, (select count(r.OI) from Report r where aci.ACIOI = r.ACIOI) as ReportCount, ci.Name, aci.BusinessName, ci.[Address] As StreetAddress, ci.Town, ci.Zip, ci.Phone from AdditionalCustomerInformation aci left join CustomerInformation ci on ci.ACI_OI = aci.ACIOI where (select count(r.OI) from Report r where aci.ACIOI = r.ACIOI) >= 1" 
     >   
     </asp:SqlDataSource> 

回答

3

这编译对我蛮好:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ProviderName="System.Data.SqlClient" SelectCommand="select aci.ACIOI, 
aci.AccountNum, (select count(r.OI) from Report r where aci.ACIOI = r.ACIOI) as ReportCount, 
ci.Name, aci.BusinessName, 
ci.[Address] As StreetAddress, ci.Town, 
ci.Zip, ci.Phone 
from AdditionalCustomerInformation aci left join CustomerInformation ci on ci.ACI_OI = aci.ACIOI 
where (select count(r.OI) from Report r where aci.ACIOI = r.ACIOI) >=1"> </asp:SqlDataSource> 

...这是合乎逻辑的。只要整个SQL语句用SelectCommand属性的引号括起来,编译器就不应该在乎你的标记是否分解成单独的行。

它出现的问题是因为SQL语句中的>符号。有两种方法可以逃避该符号。你可以简单地使用&gt; HTML实体代替,如下:需要

SelectCommand = "SELECT.... &gt;= 1" 
+0

SelectCommand = @“SELECT ...”在ASP.NET标记中无效 – Greg 2009-04-09 18:07:49

1

HTML转义。将您的>替换为& GT;

同样,<变成& lt;

相关问题