0

Greetings from Appdev (i'm new to Crystall Report)

I was Creating a web application which will contains a crystal report.

My Requirement is:

The report should be displayed Based on the value (textbox in web form) which is given in textbox.

Eg: if Textbox value = 2 means only the item which has id 2 should only get display.

My crystal report has 3 sub Reports like cheque,Party(which also contains values from other table called voucher) and finally bank. these 4 tables are linked by 1 common field called 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#

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 This is the Result of my code

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

**"

Appdev
  • 189
  • 2
  • 6
  • 28

1 Answers1

0

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:

  "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

Abdulrahman_88
  • 545
  • 1
  • 5
  • 15
  • Hi thanks for your respond...and we can use above code to pass parameter to sub reports also????. – Appdev Jun 13 '14 at 05:12