简体   繁体   English

我如何通过文本框C#WebForm将参数传递给Crystal报表中的子报表

[英]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的公共字段链接。

  1. need to know how to pass parameter to crystall report. 需要知道如何将参数传递给晶体报告。
  2. How to display the result only once (my code display same result twice) 如何只显示一次结果(我的代码两次显示相同结果)

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.

相关问题 如何在C#中将数据从文本框传递到同一Web窗体中的标签? - How to pass data from a textbox to a label in the same webform in c#? 如何在C#中将组合框值作为参数传递给Crystal Report - how to pass combo box value as a parameter to crystal report in c# 将文本框值传递给Crystal Report参数c# - Passing Textbox value to Crystal Report Parameter c# 将图像路径作为参数传递给水晶报告 c# 中的图像 - pass image path as parameter to image in crystal report c# 将参数从C#传递到Crystal Reports - Pass parameter from C# to Crystal Reports 在 C# 中,如何设置默认的 Crystal Report 参数但仍然在参数对话框中看到此参数 - From C#, how to set default Crystal Report parameter but still see this parameter in the parameter dialog 如何在C#(Visual Studio 2013)中使用Crystal Report 8.5将参数传递给存储过程? - How to pass parameter to a stored procedure in using Crystal Report 8.5 at C# (visual studio 2013)? 如何使用C#将组合框选定的值添加到水晶报表文本框中 - How I add a combobox selected value to crystal report textbox using C# 结合使用C#和Crystal Reports,如何创建4-Up子报表? - Using C# with Crystal Reports, How Can I Create 4-Up Subreports? 如何使用C#从WebForm中的禁用文本框中获取值 - How to get the value from a disabled textbox in WebForm using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM