Using Studio 2010 C# - with sqldatasource querying DB2 UDB database.
I have a gridview sqldatasource that uses a WHERE condition as follows:
Select values WHERE groupname IN ('groupa','groupb',etc.)
Works fine hardcoded in the sqldatasource but I want to create the group list in the code-behind and plug it into the SelectParameters.
So far - I have changed my sqldatasource select statement to: Select values WHERE groupname IN ?
Next, I am building a string in the code behind as follows:
string gList = "('groupa', 'groupb')";
This is a variable list of groups from another data source.
Next, I moved the string to a Session string so that it's available throughout my session as follows:
Session["aGrps"] = gList;
Then I use the session string in my selectparameters of the sqldatasource as follows:
<SelectParameters> <asp:SessionParameter Name="aGrps" Type="String" <SessionField="aGrps" /> </SelectParameters>
The sql statment does not work.
I get data if gList is only one group with no quote or paren characters as follows:
string gList = "groupa";
But when I try to add more groups in the list with or without any special characters like quotes, parens, or commas - I get no data. Not sure that's causing the problem - but then again...?
Is there a problem with using WHERE IN ? Or am I going about this all wrong? Any assistance in building this WHERE claue would be appreciated.
Thanks