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();
当我尝试将SelectParameters
添加到我的SqlDataSource
中时,我得到一个错误:
必须声明标量变量“@FacilityID”
我在aspx页面中手动输入了选择参数,它与我参数化的其他2个值一起工作得很好。我想尝试在我的代码中这样做。有人有什么见解吗?
这是我的SqlDataSource1
的aspx页面。这个很好用,但是我不能用其他方式。
<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>
1条答案
按热度按时间qvtsj1bj1#
<%--
bee sting意味着FacilityID
参数被注解掉了。在与数据源一起使用时不声明它。