-2

How do I take this string and drop it into the select command?

    String SqlC = "select * from dbo.FindIt where " + SqlStr;

The object is to populate the SelectCommand:

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:M3ConnectionString %>" 
     SelectCommand = SqlC >
</asp:SqlDataSource>
1

1 Answer 1

0
protected void Page_Load(object sender, EventArgs e)
{
    var runx = Request.QueryString.GetValues("run") != null ? Request.QueryString.GetValues("run")[0] : "";
    if (runx != "") {
       var sqlStr = "RUN= '" + Runx + "'";
       var sqlC = "select * from dbo.FindIt where " + sqlStr;
       SqlDataSource1.SelectCommand = sqlC;
    }
    else {
       // TODO: Handle this situation.
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

If I go to the Design tab and double click the form, it created a Page_Load script. but I get the error "the name SqlC does not exist in the current context."
Start of the page ``` <%@ Page Language="C#" %> <% String Runx = Request.QueryString.GetValues("run") != null ? Request.QueryString.GetValues("run")[0] : ""; if (Runx != "") { SqlStr = "RUN= '" + Runx + "'"; } String SqlC = "select * from dbo.FindIt where " + SqlStr; %> <!DOCTYPE html> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { SqlDataSource1.SelectCommand = SqlC; } </script> ```
@Juliemac Please see my revision. Can you simply move all of that logic into the Page_Load method?
That was it. Perfect!

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.