SqlDataAdapter adpReport;
      
DataSet dsReport;
        
ReportDataSource rds = new ReportDataSource();
strSQL = "SELECT ********* WHERE Facility.FacilityId = @FacilityID and DirectDepositRejections.TransactionDate >= @txtFromDate And DirectDepositRejections.TransactionDate <= @txtToDate";
using (SqlConnection conn = new SqlConnection(DBConnection.connectionString()))
{
    conn.Open();
    using (SqlCommand cmd = new SqlCommand(strSQL, conn))
    {
        cmd.Parameters.AddWithValue("@FacilityID", Session["facilityID"].ToString());
        cmd.Parameters.AddWithValue("@txtFromDate", txtFromDate.Text);
        cmd.Parameters.AddWithValue("@txtToDate", txtToDate.Text);
        adpReport = new SqlDataAdapter(cmd);
        dsReport = new DataSet("TransactionHistory_ResidentTransactions");
        adpReport.Fill(dsReport, "TransactionHistory_ResidentTransactions");
        rds.Name = "RejectionReport_RejectionDataSet";
        rds.Value = dsReport.Tables[0];
                
        rptvwRejectionTransactions.LocalReport.DataSources.Add(rds);
        rptvwRejectionTransactions.LocalReport.DataSources[0].DataSourceId = "SqlDataSource1";
SqlDataSource1.InsertParameters.Add("@r.FacilityID", System.Data.DbType.String, Session["FacilityID"].ToString());
        SqlDataSource1.SelectCommand = strSQL;
        SqlDataSource1.DataBind();
    }
    ReportParameter[] params1 = new ReportParameter[1];
    params1[0] = new ReportParameter("FacilityID", Session["FacilityID"].ToString(), false);
    rptvwRejectionTransactions.LocalReport.SetParameters(params1);
    rptvwRejectionTransactions.LocalReport.Refresh();
When I tried to add SelectParameters to my SqlDataSource, I get an error:
Must declare the scalar variable "@FacilityID"
I've manually input the Select Parameters in the aspx page and it works fine with the other 2 values that I've parameterized. I want to try doing it within my code. Do anyone have any insights?
This is my aspx page for my SqlDataSource1. This works fine, but I can't do it the other way.
<SelectParameters>
    <%--<asp:SessionParameter Name="FacilityID" SessionField="FacilityID" Type="Int32" />--%>
    <asp:ControlParameter Name="txtFromDate" ControlID="txtFromDate" Type="String"/>
    <asp:ControlParameter Name="txtToDate" ControlID="txtToDate" Type="String"/>
</SelectParameters>