我尝试正确定义@NumOfTransactions
的控制参数,但收到错误“PropertyName必须设置为控制参数”NumOfTransactions“中名为”rptvwTransactionResearch“的控件的有效属性名。
我的aspx文件
<table style="height: 400px; width: 100%;">
<tr>
<td style="vertical-align: top; text-align: left" >
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<rsweb:ReportViewer ID="rptvwTransactionResearch" runat="server" Height="333px" Width="100%" Visible="False" SizeToReportContent="True">
<LocalReport ReportPath="Reports\rptTransactionResearch.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="SqlDataSource1" Name="TransactionResearch_ResidentResearch" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BANKMDFConnectionString %>"
SelectCommand="SELECT r.ResidentID, r.FirstName, r.LastName, rt.TransactionDate, CASE WHEN CharIndex(' From ', rt.TransactionDescription) > 0 THEN substring(rt.TransactionDescription, charindex(' From ', rt.TransactionDescription) + 6, (Len(rt.TransactionDescription) - charindex(' From ', rt.TransactionDescription) + 6)) ELSE ' ' END AS TransactionDescription,rt.Amount FROM Resident AS r LEFT OUTER JOIN ResidentTransactions AS rt ON r.FacilityID = rt.FacilityID AND r.ResidentID = rt.ResidentID WHERE (r.FacilityID = @FacilityID) AND ( @NumOfTransactions = (SELECT count(1) FROM ResidentTransactions WHERE (FacilityID = r.FacilityID) AND residentid = r.residentid)) AND (( (rt.TransactionDate = (SELECT MAX(TransactionDate) AS Expr1 FROM ResidentTransactions AS ResidentTransactions_1 WHERE (FacilityID = r.FacilityID) AND (ResidentID = r.ResidentID) AND (DepositWithdrawalCode = 'D'))) AND (rt.TransactionSeq = (SELECT MAX(TransactionSeq) AS Expr1 FROM ResidentTransactions AS ResidentTransactions_1 WHERE (FacilityID = r.FacilityID) AND (ResidentID = r.ResidentID) AND (TransactionDate = rt.TransactionDate) AND (DepositWithdrawalCode = 'D'))) ) OR Transactionseq is null) Order by ltrim(r.LastName),ltrim(r.FirstName) ">
<SelectParameters>
<asp:SessionParameter Name="FacilityID" SessionField="FacilityID" Type="Int32" />
<asp:ControlParameter Name="NumOfTransactions" ControlId="rptvwTransactionResearch" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
下面是我的aspx.cs代码片段
using (SqlCommand cmd = new SqlCommand(strSQL, conn))
{
var numOfDays = Int32.Parse(txtParam.Text) * -1;
cmd.Parameters.AddWithValue("@FacilityID", Session["FacilityID"].ToString());
cmd.Parameters.AddWithValue("@NumOfDays", numOfDays);
cmd.Parameters.AddWithValue("@NumOfTransactions", txtParam.Text);
SqlDataAdapter adpReport = new SqlDataAdapter(cmd);
DataSet dsReport = new TransactionResearch();
dsReport = new DataSet("TransactionResearch_ResidentResearch");
var testing3 = dsReport.Tables;
adpReport.Fill(dsReport, "TransactionResearch_ResidentResearch");
rds.Name = "TransactionResearch_ResidentResearch";
rds.Value = dsReport.Tables;
rptvwTransactionResearch.LocalReport.DataSources.Add(rds);
rptvwTransactionResearch.LocalReport.ReportPath = "Reports/rptTransactionResearch.rdlc";
rptvwTransactionResearch.LocalReport.DataSources[0].DataSourceId = "SqlDataSource1";
SqlDataSource1.SelectParameters.Add("@NumOfTransactions", DbType.String, txtParam.Text);
SqlDataSource1.SelectCommand = "SELECT r.ResidentID, r.FirstName, r.LastName, rt.TransactionDate, CASE WHEN CharIndex(' From ', rt.TransactionDescription) > 0 THEN substring(rt.TransactionDescription, charindex(' From ', rt.TransactionDescription) + 6, (Len(rt.TransactionDescription) - charindex(' From ', rt.TransactionDescription) + 6)) ELSE ' ' END AS TransactionDescription,rt.Amount FROM Resident AS r LEFT OUTER JOIN ResidentTransactions AS rt ON r.FacilityID = rt.FacilityID AND r.ResidentID = rt.ResidentID WHERE (r.FacilityID = @FacilityID) AND ( @NumOfTransactions = (SELECT count(1) FROM ResidentTransactions WHERE (FacilityID = r.FacilityID) AND residentid = r.residentid)) AND (( (rt.TransactionDate = (SELECT MAX(TransactionDate) AS Expr1 FROM ResidentTransactions AS ResidentTransactions_1 WHERE (FacilityID = r.FacilityID) AND (ResidentID = r.ResidentID) AND (DepositWithdrawalCode = 'D'))) AND (rt.TransactionSeq = (SELECT MAX(TransactionSeq) AS Expr1 FROM ResidentTransactions AS ResidentTransactions_1 WHERE (FacilityID = r.FacilityID) AND (ResidentID = r.ResidentID) AND (TransactionDate = rt.TransactionDate) AND (DepositWithdrawalCode = 'D'))) ) OR Transactionseq is null) Order by ltrim(r.LastName),ltrim(r.FirstName)";
SqlDataSource1.DataBind();
}
我面临的问题是,当我将查询字符串传递给SqlDataSource1并设置SelectParameters
时,似乎没有注册该参数,从而导致错误Must Declare Scarlar Variable '@NumOfTransactions
。
1条答案
按热度按时间abithluo1#
您似乎错过了@