如何以编程方式生成多份水晶报表(详细节)? [英] How can I programmaticly produce multiple copies of Crystal Reports (Details Section)?

查看:253
本文介绍了如何以编程方式生成多份水晶报表(详细节)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页要求用户输入一个输入编号,并根据输入执行SQL查询,然后获取结果以填充Crystal Reports页面。这里是搜索数据库并填充报告的代码:(为了简单起见,我删除了很多不会为问题添加值的查询字符串,Crystal Reports字段也一样)

I have a web page that asks the user for an input number and based on the input, an SQL query is executed and the results is then fetched to fill a Crystal Reports page. Here is the code that searches the database and fills the report: (For simplicity, I removed a lot of query string that does not add value to the question, same goes for Crystal Reports fields)

Dim sql As String = ""
sql = " SELECT * from table1 where input_id = '" & INPUT_NUMBER & "'"

Dim ds As DataSet = getTable(sql)
Dim orpt As New CrystalReport3
CrystalReportViewer1.ReportSource = orpt
orpt.DataDefinition.FormulaFields("fldMaterialID").Text = """" & ds.Tables(0).Rows(0).Item("MATERIAL_ID").ToString & """"
orpt.DataDefinition.FormulaFields("fldMaterialID2").Text = """" & ds.Tables(0).Rows(0).Item("MATERIAL_ID").ToString & """"
orpt.DataDefinition.FormulaFields("fldBar").Text = """" & ds.Tables(0).Rows(0).Item("MATERIAL_ID_BAR_CODE").ToString & """"
orpt.Refresh()

我试图允许用户查看报告的多个副本。我已尝试:

I am trying to allow the user to view multiple copies of the report. I already tried:

 orpt.PrintToPrinter(2, False, 0, 1)

但这没有用。我搜索谷歌,StackOverflow,但我得到的所有解决方案与Crystal Reports与保存的查询,这不是一个选项。非常感谢任何帮助。

But that did not work. I searched Google, StackOverflow but all the solutions I get are related to Crystal Reports with Saved Queries which is not an option for me. Any help is much appreciated.

推荐答案

我终于做到了。

对于那些想知道如何或为了更好的 StackOverFlow.com 经验的人,我很高兴共享解决方案。

For those who would like to know how, or for a better StackOverFlow.com experience, I am glad to share the solution.

阅读这篇伟大的文章,我受到了解决方案的启发,并能够通过

After reading this great article, I was inspired by the solution and was able to accomplish the desired result by

1 - 替换FormulaFields一个 ADO数据集包含相同数目的列
我通过在VS.2008中创建一个新的DataSet并命名为 adoDataSet 。然后添加所有必需的列名称(此时没有链接到实际的数据,因为数据将被动态拉动,这只是数据的模板)。默认情况下,所有列都将是String类型,但是对我的情况来说。

1-Replacing the FormulaFields with an ADO dataset containing the same number of columns I did that by creating a new DataSet in VS.2008 and named it adoDataSet. Then added all required column names to it (No linking to the actual data at this point as the data will be pulled dynamically later. This is just like a template for the data only). By default, all columns will be String typed, but that okay for my case.

在水晶报表中,我使用DataBase Expert将上述数据集并将公式字段的位置替换为adoDataSet中的列

3- In Crystal Reports, I used DataBase Expert to pull the mentioned dataset into the report and replaced the locations of the formula fields with the columns from the adoDataSet

4然后在我的代码中,用数据填充公式字段,我只是调用了相同的函数一个SQL查询并返回一个正常的OracleClient数据集(所以它可能会根据需要返回多行)

4- Then in my code to populate the formulafields with data, I just called the same function that takes an SQL query and returns a normal OracleClient data set (so it might return multiple rows as desired)

5-此数据集不能直接用于Crystal Reports,因此必须首先转换为之前创建的相同类型的 adoDataSet 。所以一个简单的 TryCast 为我做了。

5- This dataset however can not be used directly with Crystal Reports, so it must be first converted to the same type of the adoDataSet created earlier. so a simple TryCast did that for me.

Dim sql As String = ""
sql = " SELECT * from table1 where input_id = '" & INPUT_NUMBER & "'"

Dim ds As DataSet = getTable(sql)
Dim orpt As New CrystalReport3
CrystalReportViewer1.ReportSource = orpt
dim ds1 as New adoDataSet
ds1 = TryCast(ds,adoDataSet)   ' ds is based on OracleClient data set
                        ' while adoDataSet is the one CrystalReports likes to use
orpt.SetDataSource(ds1)

我能够生成尽可能多的副本,因为我拥有数据,并且可以导致数据显示多次我喜欢。

from there I was able to generate as much copies as I wanted because I own the data, and can cause the data to appear as many times as I like.

这篇关于如何以编程方式生成多份水晶报表(详细节)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆