如果与ASP.NET一起使用,则SQL的子句不起作用

编程入门 行业动态 更新时间:2024-10-18 23:29:31
本文介绍了如果与ASP.NET一起使用,则SQL的子句不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好, 我在SQLdatasource中的where条件中使用IN子句,该条件被分配给gridview。我使用HiddenField为IN子句提供值。如果它有单个值然后它工作正常但如果它有多个值然后结果是空的 我尝试过:

服务器端vb < pre> HiddenField1.Value =864180030063601,111111111111111

Asp 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的子句不起作用

本文发布于:2023-11-28 07:05:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子句   不起作用   ASP   NET   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!