Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 different table like cheque,Party and finally bank. these 3 tables are linked by 1 common field called id.

need to know how to pass parameter(id) to crystal report.

while seeing the preview it was displaying properly.
but i dnt know how to send id from .cs to crystal report.

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("TransReceipt.rpt");
              CRReport = new ReportDocument();
              CRReport.Load(reportPath);
              CrystalReportViewer1.ReportSource = CRReport;

             ////////////////////////////////////////////////////////////////////////////////////////////////

              ParameterFieldDefinitions crParameterFieldDefinitions;
              ParameterFieldDefinition crParameterFieldDefinition;
              ParameterValues crParameterValues = new ParameterValues();
              ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

              crParameterDiscreteValue.Value = Session["ID"];
              crParameterFieldDefinitions = CRReport.DataDefinition.ParameterFields;
              crParameterFieldDefinition = crParameterFieldDefinitions["IDP"]; 
              crParameterValues = crParameterFieldDefinition.CurrentValues;

              crParameterValues.Clear();
              crParameterValues.Add(crParameterDiscreteValue);
              crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

              CrystalReportViewer1.ReportSource = CRReport;
              CrystalReportViewer1.RefreshReport();
              ////////////////////////////////////////////////////////////////////////////////////////////////

              // ConnectionInfo connectionInfo = ConnInfo();
              ConnectionInfo objConnInfo = new ConnectionInfo();
              objConnInfo.DatabaseName = "Demo";
              objConnInfo.UserID = "sa";
              objConnInfo.Password = "xxx";
              objConnInfo.ServerName = "HOME-PC\\SQLEXPRESS";
              SetDBLogonForReport(objConnInfo, CRReport);
              SetDataSetForMultipleSubReport(objConnInfo, CRReport);

          }
      }


and this is the line i'm getting error

crParameterFieldDefinition = crParameterFieldDefinitions["IDP"];


can any one help to resolve this.
Thanks in advance
Posted
Comments
[no name] 13-Jun-14 4:02am    
in my report i have generated a parameter in the name of IDP and set that value type to number.

1 solution

Hello ,
You may take one TextObject in your crystal report and change its value according to your requirement . and then load your crystal report depending upon the value .

try this code
CrystalReport1 sr = new CrystalReport1();
 
TextObject txtvalue = (TextObject)sr.ReportDefinition.ReportObjects["txtobject"];
// "txtobject" is the TextObject, name mentioned on Crystal Report Viewer.
 txtvalue.Text = "value";//set the value 

//other coding....

crystalReportViewer1.ReportSource = sr;
crystalReportViewer1.Refresh();


thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900