sqldatasource中的语法selectcommand

时间:2010-04-07 12:38:20

标签: asp.net sqldatasource

我的SqlDataSource select命令由Eval单向数据绑定语法的String.Format功能动态更改。它工作正常。但是我需要将两个列值放在一起,中间有一个空格(ItemType +'“”'+ ItemDescription As ItemInfo)但是我收到消息时无法正确获取语法:“服务器标签格式不正确“

你能帮忙吗?非常感谢

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conn %>" SelectCommand='<%# Eval("TypeID", "SELECT ItemID, ItemType, ItemType + '" "' + ItemDescription As ItemInfo WHERE ItemType = {0}")%>'> </asp:SqlDataSource>

2 个答案:

答案 0 :(得分:0)

可能是一个更普遍的问题
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
         ConnectionString="<%$ConnectionStrings:conn %>" 
         SelectCommand='<%# Eval(&quot;TypeID&quot;, &quot;SELECT ItemID, ItemType, ItemType + &quot;\" \"&quot; + ItemDescription As ItemInfo WHERE ItemType = {0}&quot;)%>'> 
 </asp:SqlDataSource>

答案 1 :(得分:0)

HiI以这种方式解决了这个问题(正如How to use Single Quotes in Eval Format String中所述)

在items.aspx.vb

Protected Const SqlQuery As String = "SELECT ItemID, ItemType, ItemType + " + "' '" + " ItemDescription As ItemInfo WHERE ItemType = {0}"

在items.aspx

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conn %>" SelectCommand='<%# Eval("TypeID", SQLQuery)%>'> </asp:SqlDataSource>

非常感谢