tags:

views:

120

answers:

2

I have a sql data source and I have a really long string of SQL. I want to put linebreaks in my sql but Visual Studio doesn't seem to like the linebreaks. How would I put in line breaks?

Example

<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  A: 

This compiles just fine for me:

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

... which is logical. The compiler should not care if your markup is broken up into separate lines as long as the entire SQL statement is enclosed in quotes of the SelectCommand property.

The problem it appears is because of the > symbol in your SQL statement. There are two ways to escape that symbol. You could simply use the &gt; HTML entity instead, as follows:

SelectCommand = "SELECT.... &gt;= 1"
Cerebrus
SelectCommand = @"SELECT ..." is not valid in ASP.NET markup
Greg
Ahh, Thanks for the heads up. I seem to recall reading that it works sometime back.
Cerebrus
FYI - The @ in your last example is still there.
Greg
Damb it! Thanks again. :-)
Cerebrus
+1  A: 

HTML escaping is required. Replace your > with &gt;

Likewise, < becomes &lt;

Greg