SelectCommand error:Validation(ASP.NET) 如果此属性值用引号括起来,则引号必须匹配
Posted
技术标签:
【中文标题】SelectCommand error:Validation(ASP.NET) 如果此属性值用引号括起来,则引号必须匹配【英文标题】:SelectCommand error:Validation(ASP.NET) If this attribute value is enclosed en quotation marks, the quotation marks must match 【发布时间】:2018-08-15 10:35:13 【问题描述】:我在 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>
【问题讨论】:
【参考方案1】:您需要将查询中的单引号和小于号替换为 XML 实体引用 &quot;
和 &lt;
,以便 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>
【讨论】:
以上是关于SelectCommand error:Validation(ASP.NET) 如果此属性值用引号括起来,则引号必须匹配的主要内容,如果未能解决你的问题,请参考以下文章
System.InvalidOperationException:“填充:SelectCommand.Connection 属性尚未初始化。”
SqlDataAdapter#Fill:`SelectCommand.connection` 属性尚未初始化
system.invalidoperationexception:填充:selectCommand.Connection 属性尚未初始化