使用Crystal Reports从SQL DB中获取单行

时间:2015-05-20 15:45:21

标签: c# pdf datatable crystal-reports

我遇到了一个问题,我的水晶报告正在创建每条记录的pdf页面,尽管数据表被解析为只包含一行的pdf代。

我有一个查询,它根据Id选择一行,然后放入数据集数据表并解析为水晶报告生成。

单步执行我可以确认数据表只包含一行,但输出是pdf的多个页面,每个页面都显示不同的行。

之前有没有人遇到过这个问题,如果有的话,是什么原因导致我的数据集被侵入?

代码背后:

public string CreateMaster(int Id)
        {
            DataTable dt = DataGrabber(Id);// returns a dataset
            ExportOptions expo = new ExportOptions();
            PdfRtfWordFormatOptions form = new PdfRtfWordFormatOptions();
            string op = "";
            string smp = DateTime.Now.ToString("yyyyMMddHHmm");
            DiskFileDestinationOptions dfd = new DiskFileDestinationOptions();
            op = @"E:\SomeFolder\Client_ID" + Id + "_TS"+ smp + ".pdf";

            using (ClientDdPdf pdf = new ClientDdPdf())
            {
                pdf.PrintOptions.PaperOrientation = PaperOrientation.Portrait;
                pdf.PrintOptions.PaperSize = PaperSize.PaperA4;
                pdf.SetDatabaseLogon(DbUser,DbPass,DbServer,DbDb);
                pdf.SetDataSource(dt); // confirmed that the single datatable from dataset is parsed
                dfd.DiskFileName = op;
                expo = pdf.ExportOptions;
                expo.ExportDestinationType = ExportDestinationType.DiskFile;
                expo.ExportFormatType = ExportFormatType.PortableDocFormat;
                expo.DestinationOptions = dfd;
                expo.ExportFormatOptions = form;
                pdf.Export(expo);
            }
            ReadPdfFile(op);
            return op;
        }

1 个答案:

答案 0 :(得分:0)

不完全确定为什么会出现这个问题,但是当它在水晶报表中有查询时,它不像我正在解析的自定义查询。

为此找到的解决方案是将水晶报告映射到视图。基本上,这仍然是从相同的表中获取相同的字段,但确实需要在数据表中解析并生成所需的字段。

为了澄清,我根本没有改变我的代码,我仍然使用相同的查询来获取必要的数据表,但是当将水晶报表绑定到数据库时,我没有绑定它是表格,但是我创建的视图。