Populating the SQLDatasource SelectCommand

53 views Asked by At

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

There are 1 answers

4
Jim G. On
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.
    }
}