Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I have the following SQLDataSource:

<asp:SqlDataSource runat="server" ID="MySqlDataSource" ConnectionString='<%$ ConnectionStrings:RmaReportingConnectionString %>' 
     SelectCommand="SELECT DISTINCT [Team] FROM [Locations] WHERE ([Team] IN (@Teams))">
        <SelectParameters>
             <asp:Parameter Name="Teams" Type="String" />
        </SelectParameters>
 </asp:SqlDataSource>

In code behind calling it like this:

MySqlDataSource.SelectParameters["Teams"].DefaultValue = "'Team 1','Team 2'";
MySqlDataSource.DataBind();

The issue is that I am not getting any results and I have a feeling it is due to syntax because if I run the raw SQL without the Parameter it works fine.

share|improve this question
    
I'm pretty sure it's impossible to use parameters with the IN clause. I'm not answering as I'm not 100% positive, but that would explain why it works as raw SQL – freefaller Aug 20 at 8:08
    
Possible, due to the '' characters. if not then what could be an alternative? – sd_dracula Aug 20 at 8:10

2 Answers 2

up vote 0 down vote accepted

This could be because of the escape characters (') in your string.

Try adding an @ sign before your variable string:

MySqlDataSource.SelectParameters["Teams"].DefaultValue = @"'Team 1','Team 2'";
share|improve this answer
SELECT DISTINCT [Team] FROM [Locations] WHERE ([Team] IN (@Teams))

this will only return 1 result. you need to mention all conditions like

 SELECT DISTINCT [Team] FROM [Locations] WHERE ([Team] IN (@Team1,@Team2,@Team3))
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.