Reputation: 46222
I have the following in my .aspx
file
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KrySQL %>" OnSelecting="DataSourceSelecting"
SelectCommand="Select ID, RoomNum from [dbo].[MBiology] WHERE LocId IN @LocId" >
<SelectParameters>
<asp:Parameter Name="LocId" />
</SelectParameters>
</asp:SqlDataSource>
My goal is to pass a comma delimited list or just one value for @LocId
In my code behind, I have the following:
SqlDataSource1.SelectParameters["LocID"].DefaultValue = "(" + valint.ToString() + ")";
I thought this should work as I have the parenthesis and all.
I am getting the following error message:
Incorrect syntax near '@LocId'
Upvotes: 0
Views: 424
Reputation: 726599
Unfortunately, you cannot do it like this: .NET does not let you pass an entire list in a single SQL parameter.
There are two ways of implementing what you need:
IN
list dynamically, orUpvotes: 1