I can properly parameterize my SQL query using IN Clause using a for loop. I have trouble properly implementing the same query in my SQLDataSource. I have to literally declare the SelectParameters in my SQLDataSource markup in order for it to work properly. That limits my reference to the number of parameters that I declare. Is there a way for me to set the SelectParameters dynamically?
for (int i = 0; i < paramNamesTwo.Length; i++)
{
var residentID = paramNamesTwo[i];
var test2 = residentIDs[i];
//This line declares the markup I had for only 2
SqlDataSource1.SelectParameters[residentID].DefaultValue = test2;
}
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BANKMDFConnectionString %>"
SelectCommand="********">
<SelectParameters>
<asp:SessionParameter Name="RTResidentID" SessionField="RTResidentID" Type="String" />
//I declared it manually here twice, so I am only limited to 2 selections
<asp:SessionParameter Name="RTResidentID0" SessionField="RTResidentID0" Type="String" />
<asp:SessionParameter Name="RTResidentID1" SessionField="RTResidentID1" Type="String" />
<asp:SessionParameter Name="RTFacilityID" SessionField="RTFacilityID" Type="String" />
<asp:SessionParameter Name="RTTrustFundAcctID" SessionField="RTTrustFundAcctID" Type="String" />
<asp:Parameter Name="txtToDate" Type="String" />
<asp:Parameter Name="txtFromDate" Type="String" />
</SelectParameters>
</asp:SqlDataSource>