0
<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 ?

3
  • Well - run it - does it work?? Commented Mar 31, 2015 at 5:16
  • No,it doesn't.It does not take the value of username. Commented Mar 31, 2015 at 5:18
  • try change the SelectCommand to SelectCommand="SELECT * FROM [Table] where Owner like @username"> Commented Mar 31, 2015 at 5:35

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

there is a difference between @username and '@username', 2nd one is no longer a parameter, it consider as string value.
I initially tried data binding actually,something like <%#username%> but that did not work either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.