开发者

syntax in sqldatasource selectcommand

开发者 https://www.devze.com 2022-12-26 13:51 出处:网络
My SqlDataSource selectcommand is dynamically changed by the String.Format functionality of the Eval one-way databinding syntax. It works ok. However I need to put together two colu开发者_如何学编程mn

My SqlDataSource selectcommand is dynamically changed by the String.Format functionality of the Eval one-way databinding syntax. It works ok. However I need to put together two colu开发者_如何学编程mns values with a space in the middle (ItemType + '" "' + ItemDescription As ItemInfo) but I can't get the syntax correct as I get the message: "The server tag is not well formed"

Can you help? Many thanks

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


It could be a more general issue with "

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


HiI resolved the issue in this way (as advised in How to use Single Quotes in Eval Format String )

In items.aspx.vb

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

In items.aspx

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

Many thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号