[英]How do i pass parameter to subreports in crystal report from textbox c# webform
Greetings from Appdev (i'm new to Crystall Report) 来自Appdev的问候(我是Crystall Report的新手)
I was Creating a web application which will contains a crystal report. 我正在创建一个Web应用程序,其中将包含一个水晶报表。
My Requirement is: 我的要求是:
The report should be displayed Based on the value (textbox in web form) which is given in textbox. 报告应基于文本框中提供的值(Web表单中的文本框)显示。
Eg: if Textbox value = 2 means only the item which has id 2 should only get display. 例如:如果“文本框”值= 2,则仅显示ID为2的项目。
My crystal report has 3 sub Reports like cheque,Party(which also contains values from other table called voucher) and finally bank. 我的水晶报表有3个子报表,例如cheque,Party(其中还包含来自其他表的值,称为voucher),最后是bank。 these 4 tables are linked by 1 common field called id. 这4个表由1个称为id的公共字段链接。
this is how i bind the crystal report using parameters from .cs file in c# 这是我如何使用c#中的.cs文件中的参数绑定Crystal报表
public void LoadTransReceipt()
{
string Date = "";
string Sql = "SELECT tREC_NUPKId as ID from TB_TransReceipt where tREC_VCVoucherNo='" + TXTVou.Text.Trim() + "' and tREC_NUIsActive=1";
SqlDataReader rdr = mobjGenlib.objDBLib.ExecuteQueryReader(Sql.ToString());
while (rdr.Read())
{
Session["ID"] = rdr.GetValue(0).ToString();
}
rdr.Close();
if (!string.IsNullOrEmpty(Session["ID"] as string))
{
if (Session["Date"] != null)
{
Date = mobjGenlib.ConvertString(Session["Date"]);
}
reportPath = GetReportPath("ReceiptReport.rpt");
CRReport = new ReportDocument();
CRReport.Load(reportPath);
CrystalReportViewer1.ReportSource = CRReport;
AddParameterToReport("IDP", Session["ID"].ToString());
AddParameterToReport("ActiveP", 1);
AddParameterToReport("IDB", Session["ID"].ToString());
AddParameterToReport("ActiveB", 1);
AddParameterToReport("IDC", Session["ID"].ToString());
AddParameterToReport("ActiveC", 1);
// ConnectionInfo connectionInfo = ConnInfo();
ConnectionInfo objConnInfo = new ConnectionInfo();
objConnInfo.DatabaseName = "Demo";
objConnInfo.UserID = "aa";
objConnInfo.Password = "aaaa";
objConnInfo.ServerName = "HOME-PC\\SQLEXPRESS";
SetDBLogonForReport(objConnInfo, CRReport);
SetDataSetForMultipleSubReport(objConnInfo, CRReport);
}
}
but when i execute the code it displaying all data's available in table with double time like shown below 但是当我执行代码时,它会以两倍的时间在表中显示所有数据,如下所示
can any one help me to solve this issue 谁能帮我解决这个问题
Thanks in advance 提前致谢
getting error as 作为错误
" ** **
Specified argument was out of the range of valid values 指定的参数超出有效值范围
**" **”
From Field Explorer in the report right click add new parameter, then in code behind you have to set the value of the parameter like: 在报表的“字段资源管理器”中,右键单击添加新参数,然后在后面的代码中必须设置参数的值,例如:
CRReport.SetParameterValue("@Parameter", TXTVou.Text)
You can prevent the duplication by add the word DISTINCT to your Query like: 您可以通过在查询中添加单词DISTINCT来防止重复,例如:
"SELECT DISTINCT tREC_NUPKId as ID from TB_TransReceipt where tREC_VCVoucherNo='" + TXTVou.Text + "' and tREC_NUIsActive=1"
or You can prevent the duplication by (Suppress If Duplicated) property in the field 或您可以通过字段中的(如果重复则抑制)属性来防止重复
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.