How to use Crystal Reports without a tightly-linked DB connection?

前端 未结 2 987
悲&欢浪女
悲&欢浪女 2020-12-19 15:16

I\'m learning to use Crystal Reports (with VB 2005).

Most of what I\'ve seen so far involves slurping data directly from a database, which is fine if that\'s all you

相关标签:
2条回答
  • 2020-12-19 16:05

    Go ahead and create the stock object as described in the link you posted and create the report (StockObjectsReport) as they specify. In this simplified example I simply add a report viewer (crystalReportViewer1) to a form (Form1) and then use the following code in the Form_Load event.

    stock s1 = new stock("AWRK", 1200, 28.47);
    stock s2 = new stock("CTSO", 800, 128.69);
    stock s3 = new stock("LTWR", 1800, 12.95);
    
    ArrayList stockValues = new ArrayList();
    
    stockValues.Add(s1);
    stockValues.Add(s2);
    stockValues.Add(s3);
    
    ReportDocument StockObjectsReport = new StockObjectsReport();
    StockObjectsReport.SetDataSource(stockValues);
    
    crystalReportViewer1.ReportSource = StockObjectsReport;
    

    This should populate your report with the 3 values from the stock object in a Windows Form.

    EDIT: Sorry, I just realized that your question was in VB, but my example is in C#. You should get the general idea. :)

    0 讨论(0)
  • 2020-12-19 16:18

    I'm loading the report by filename and it is working perfect:

    //........
    
    ReportDocument StockObjectsReport;
    
    string reportPath = Server.MapPath("StockObjectsReport.rpt");
    
    StockObjectsReport.Load(reportPath);
    
    StockObjectsReport.SetDataSource(stockValues);
    
    //Export PDF To Disk
    
    string filePath = Server.MapPath("StockObjectsReport.pdf");
    
    StockObjectsReport.ExportToDisk(ExportFormatType.PortableDocFormat, filePath);
    
    0 讨论(0)
提交回复
热议问题