Quantcast
Channel: Crystal Reports
Viewing all articles
Browse latest Browse all 1507

How to pass Parameter in Crystal report having two Sub report in C#.net and ASP.net

$
0
0

Hi All

   I created a report in Crystal Report and Bind with a storedprocedure which needs to parameter to executes. I want to pass it from Page_Load event of webpage to run and print report. Code is as bellow

 

Following code not worked and prompting pass for parameters before executing report

----------------------------------------------------------------------------------------------------------------

ReportDocument rptDoc = new ReportDocument();

strReportPath = Server.MapPath(Session["REPORTNAME"].ToString());

 rptDoc.Load(strReportPath);

rptDoc.SetParameterValue(0, Request.QueryString["Val1"].ToString());
 rptDoc.SetParameterValue(1, Request.QueryString["Val2"].ToString());
 rptDoc.Refresh();

ConnectionInfo dbConnInfo = new ConnectionInfo();

                    dbConnInfo.ServerName = ".";
                    dbConnInfo.DatabaseName = "xxxxxx";
                    dbConnInfo.UserID = "sa";
                    dbConnInfo.Password = "xxxxxxx";

                    TableLogOnInfo tblLogOnInfo = new TableLogOnInfo();
                    Database db = rptDoc.Database;
                    Tables tbls = db.Tables;

                    foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in tbls)
                    {
                        tblLogOnInfo = tbl.LogOnInfo;
                        tblLogOnInfo.ConnectionInfo = dbConnInfo;
                        tbl.ApplyLogOnInfo(tblLogOnInfo);
                    }

      CV1.ReportSource = rptDoc;

     CV1.RefreshReport();

----------------------------------------------------------------------------------------------------------

I also tried following code again runs without error but asking parameter pass page before executing that I dont want.

--------------------------------------------------------------------------------------------------------------------------------------

ParameterFields pfields = new ParameterFields();
                        ParameterField pfield = new ParameterField();
                        ParameterDiscreteValue disvalue = new ParameterDiscreteValue();

                        ParameterField pVoucherNo = new ParameterField();
                        ParameterDiscreteValue disVoucherNo = new ParameterDiscreteValue();

                        disvalue.Value = Request.QueryString["Val1"].ToString();
                        pfield.Name = "@VoucherID";
                        pfield.CurrentValues.Add(disvalue);
                        pfields.Add(pfield);

                        pVoucherNo.Name = "@VoucherNo";
                        disVoucherNo.Value = Request.QueryString["Val2"].ToString();
                        pVoucherNo.CurrentValues.Add(disVoucherNo);
                        pfields.Add(pVoucherNo);

                        CV1.ParameterFieldInfo = pfields;
                        CV1.ReportSource = strReportPath;

                    foreach (TableLogOnInfo cnInfo in CV1.LogOnInfo)
                    {
                        cnInfo.ConnectionInfo = dbConnInfo;
                    }
                   
                    CV1.ReportSource = rptDoc;
                   //Session["REPORTDOC"];
                   // CV1.SelectionFormula = Session["RECSELFORMULA"].ToString();
                    CV1.RefreshReport();

Please help me to pass the parameter in crystal that It will not user to pass parameter.

Thanks in Advance


Viewing all articles
Browse latest Browse all 1507

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>