-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>
Jim G.
  • 15,141
  • 22
  • 103
  • 166
Juliemac
  • 7
  • 4
  • Does this answer your question? [Creating a SelectCommand in code behind which works identically to creating one in the SQLDataSource](https://stackoverflow.com/questions/11991177/creating-a-selectcommand-in-code-behind-which-works-identically-to-creating-one) – Jim G. Jan 20 '23 at 20:34

1 Answers1

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.
    }
}
Jim G.
  • 15,141
  • 22
  • 103
  • 166
  • 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." – Juliemac Jan 23 '23 at 16:16
  • 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; %> ``` – Juliemac Jan 23 '23 at 16:33
  • @Juliemac Please see my revision. Can you simply move all of that logic into the `Page_Load` method? – Jim G. Jan 23 '23 at 18:07
  • That was it. Perfect! – Juliemac Jan 23 '23 at 18:47
  • @Juliemac: If this answer helped you, please upvote it and mark it as the accepted answer. – Jim G. Jun 02 '23 at 12:14