0

How should i write an sql statement in an SqlDataSource control?

<% String inuser="john";%>
<asp:SqlDataSource ID="SqlDataSource1" 
                   runat="server" 
                   ConnectionString="..." 
                   SelectCommand="select from users where user='<%#inuser%>'??????????????" DeleteCommand="..." InsertCommand="..." 
                   UpdateCommand="...">
</asp:SqlDataSource>

1 Answer 1

6

You'd be better served setting the value in the code-behind's load event handler:

var inuser = "john";
SqlDataSource1.SelectCommand = "select from users where user = @user";
SqlDataSource1.SelectParameters.Add("@user", inuser);

You can also do it through the markup:

<asp:SqlDataSource ID="SqlDataSource1" 
                   runat="server" 
                   ConnectionString="..." 
                   SelectCommand="select from users where user=@user">
    <selectparameters>
        <asp:Parameter name="user" DefaultValue="john"/>
    </selectparameters>
</asp:SqlDataSource>
Sign up to request clarification or add additional context in comments.

Comments

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.