Click here to Skip to main content
16,018,417 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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>
Posted
Updated 25-Oct-17 22:52pm

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[^]
 
Share this answer
 
Comments
Nitin Surya 25-Oct-17 7:02am    
Is there any other way to achieve this as you have understood my requirement
Andy Lanng 25-Oct-17 7:05am    
Yes. He gave you the link!
Nitin Surya 25-Oct-17 7:19am    
i have seen it but how could i use it in asp.net code?
Nitin Surya 25-Oct-17 9:34am    
please help
OriginalGriff 25-Oct-17 9:43am    
Read it again: set up an SP and pass it the parameter.
 
Share this answer
 
Comments
Nitin Surya 15-Nov-17 9:30am    
sorry for late reply... it is better way then i was doing
Karthik_Mahalingam 15-Nov-17 9:31am    
ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900