Passing parameters to crystal reports in C#

前端 未结 5 1547
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 21:16

I\'ve been trying to get this to work for a while, and all the example code I\'ve seen aren\'t quite doing what I\'m doing.

I have a program that returns a pdf of a

相关标签:
5条回答
  • 2020-12-05 21:45
                    rptTeacherTimeTable ttReport = new rptTeacherTimeTable();
                    DataTable dt = new DataTable();
                    dt = ObjclsT_TimeTable.GetTimeTableByClass(ClassID);
    
                    objReport = ttReport;
                    objReport.SetDataSource(dt);
                    objReport.SetParameterValue("RTitle", "Class Time Table");
                    objReport.SetParameterValue("STitle", "Teacher Time Table");
                    reportViewer.crystalReportViewer1.ReportSource = objReport;
                    reportViewer.crystalReportViewer1.Show();
                    reportViewer.Show();
    
    0 讨论(0)
  • 2020-12-05 21:48

    All that parameter code can be replaced with...

    // Set datasource first
    myDataReport.SetDataSource(...)
    // Assign Paramters after set datasource
    myDataReport.SetParameterValue("MyParameter", "Hello");
    

    I can't remember if the order matters when setting the datasource and parameters. Maybe try setting the datasource first. The xsd/datasource has no relation to crystal parameters.

    UPDATE1

    SetParameterValue AFTER the datasource asignation or you will recieve error "Missing parameter values."

    0 讨论(0)
  • 2020-12-05 21:57

    just do one thing and your code will run automatically set the data source first before adding parameters...

     crp rpt = new crp();
     rpt.SetDataSource(dt);
     rpt.SetParameterValue("p",p.ToString());
    
    0 讨论(0)
  • 2020-12-05 22:02
    ReportDocument cryRpt = new ReportDocument();
    
    TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
    TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
    ConnectionInfo crConnectionInfo = new ConnectionInfo();
    Tables CrTables;
    
    string path = "C:/reportpath/report.rpt";
    cryRpt.Load(path);
    
    cryRpt.SetParameterValue("MyDate2", str2);
    cryRpt.SetParameterValue("MyDate", str1);
    
    crConnectionInfo.ServerName = "server";
    crConnectionInfo.DatabaseName = "DataBase";
    crConnectionInfo.UserID = "user";
    crConnectionInfo.Password = "password";
    
    CrTables = cryRpt.Database.Tables;
    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
    {
        crtableLogoninfo = CrTable.LogOnInfo;
        crtableLogoninfo.ConnectionInfo = crConnectionInfo;
        CrTable.ApplyLogOnInfo(crtableLogoninfo);
    }
    
    crystalReportViewer1.ReportSource = cryRpt;
    crystalReportViewer1.Refresh(); 
    
    0 讨论(0)
  • 2020-12-05 22:04
           //create object of crystal report.
            CrystalReport1 objRpt = new CrystalReport1();
            objRpt.SetDataSource(ds);
            ParameterFields pfield = new ParameterFields();
            ParameterField ptitle = new ParameterField();
            ParameterDiscreteValue pvalue = new ParameterDiscreteValue();
            ptitle.ParameterFieldName = "date";
            pvalue.Value = txtcolor.Text;
            ptitle.CurrentValues.Add(pvalue);
            pfield.Add(ptitle);
            crystalReportViewer1.ParameterFieldInfo = pfield;
            crystalReportViewer1.ReportSource = objRpt;
            crystalReportViewer1.Refresh();
    
    0 讨论(0)
提交回复
热议问题