Reputation: 19
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GSProjectConnectionString %>" SelectCommand="SELECT * FROM [Table] where Owner like '%@username%' ">
<SelectParameters>
<asp:Parameter Name="username" Type="String"/>
</SelectParameters>
</asp:SqlDataSource>
The above is my code wherein i am trying to use a variable username which is defined in .cs file.
It does not take the value of username.
Where am I going wrong ?
Any idea anyone ?
Upvotes: 0
Views: 309
Reputation: 63065
change it as
SelectCommand="SELECT * FROM [Table] where Owner like @username
when you set parameter value you can add the '%%' as below
SqlDataSource1.SelectParameters["username"].DefaultValue = string.Format("%{0}%", paramvalue);
Upvotes: 1