我在sqlserver中进行了此查询,当我在项目中将第一行显示为绿色时,标题出现错误,在第三行之后,它似乎不再位于SelectCommand内,因为它是红色字母。我认为这与<或''有关。我该如何解决?谢谢
<asp:SqlDataSource ID="ds_order" runat="server" CancelSelectOnNullParameter="false"
ConnectionString="myconnection"
SelectCommand=
"SELECT SUM(Total) as Totais, DateCreated,
CASE
WHEN DAY(DateCreated) <=15 THEN CAST(YEAR(DateCreated) AS VARCHAR) + '-' + CAST(MONTH(DateCreated) AS VARCHAR) + '-1'
ELSE CAST(YEAR(DateCreated) AS VARCHAR) + '-' + CAST(MONTH(DateCreated) AS VARCHAR) + '-16'
END AS Month
FROM Orders
WHERE ReferenceID = @refid
GROUP BY DateCreated" ProviderName="System.Data.SqlClient">
<SelectParameters>
<asp:ControlParameter ControlID="ddl_ref_type" Name="refid" />
</SelectParameters>
</asp:SqlDataSource>
答案 0 :(得分:2)
您需要用XML实体引用"
和<
替换单引号,并将其替换为查询中较少的内容,以使XML的格式正确:
<asp:SqlDataSource ID="ds_order" runat="server" CancelSelectOnNullParameter="false"
ConnectionString="myconnection"
SelectCommand=
"SELECT SUM(Total) as Totais, DateCreated,
CASE
WHEN DAY(DateCreated) <=15 THEN CAST(YEAR(DateCreated) AS VARCHAR) + "-" + CAST(MONTH(DateCreated) AS VARCHAR) + "-1"
ELSE CAST(YEAR(DateCreated) AS VARCHAR) + "-" + CAST(MONTH(DateCreated) AS VARCHAR) + "-16"
END AS Month
FROM Orders
WHERE ReferenceID = @refid
GROUP BY DateCreated" ProviderName="System.Data.SqlClient">
<SelectParameters>
<asp:ControlParameter ControlID="ddl_ref_type" Name="refid" />
</SelectParameters>
</asp:SqlDataSource>