本文介绍了如果与ASP.NET一起使用,则SQL的子句不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好, 我在SQLdatasource中的where条件中使用IN子句,该条件被分配给gridview。我使用HiddenField为IN子句提供值。如果它有单个值然后它工作正常但如果它有多个值然后结果是空的 我尝试过:
服务器端vb < pre> HiddenField1.Value =864180030063601,111111111111111Asp sqldata来源
< ; asp:SqlDataSource ID =SqlDataSource1runat =server ConnectionString =<%$ ConnectionStrings:xxxxxxxxx%> SelectCommand =SELECT * FROM [table] WHERE([column] in(@column))> < SelectParameters> < asp:ControlParameter ControlID =HiddenField1Name =columnPropertyName =ValueType =String/> < / SelectParameters> < / asp:SqlDataSource>解决方案
ConnectionStrings:xxxxxxxxx%> SelectCommand =SELECT * FROM [table] WHERE([column] in(@column))> < SelectParameters> < asp:ControlParameter ControlID =HiddenField1Name =columnPropertyName =Value Type =String/> < / SelectParameters> < / asp:SqlDataSource>
IN子句是SQL中的一种特殊情况:您不能将它们作为参数传递,因为IN在SQL命令解析序列中过早地转换为内部表以进行参数替换。 请参阅:使用逗号分隔值SQL IN子句中的参数字符串 [ ^ ]
查看此帖子 SqlDataSource - IN()子句的参数| ASP.NET论坛 [ ^ ]
hello, I am using IN clause in where condition in SQLdatasource which is assigned to gridview. I am providing values for IN clause using HiddenField. If it has single values then its works fine but if it has multi value then result is empty What I have tried:
server side vb <pre> HiddenField1.Value = "864180030063601,111111111111111"Asp sqldata source
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:xxxxxxxxx %>" SelectCommand="SELECT * FROM [table] WHERE ([column] in (@column))"> <SelectParameters> <asp:ControlParameter ControlID="HiddenField1" Name="column" PropertyName="Value" Type="String" /> </SelectParameters> </asp:SqlDataSource> 解决方案 ConnectionStrings:xxxxxxxxx %>" SelectCommand="SELECT * FROM [table] WHERE ([column] in (@column))"> <SelectParameters> <asp:ControlParameter ControlID="HiddenField1" Name="column" PropertyName="Value" Type="String" /> </SelectParameters> </asp:SqlDataSource>IN clauses are a special case in SQL: you can't pass them as a parameter, as the IN is converted to an internal table too early in the SQL command parsing sequence for parameter substitution. See here: Using comma separated value parameter strings in SQL IN clauses[^]check this post SqlDataSource - parameter for IN() clause | The ASP.NET Forums[^]更多推荐
如果与ASP.NET一起使用,则SQL的子句不起作用
发布评论