2009-04-09 46 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;

相關問題