如何以编程方式生成Crystal Reports的多个副本(详细信息部分)? [英] How can I programmatically produce multiple copies of Crystal Reports (Details Section)?

查看:71
本文介绍了如何以编程方式生成Crystal Reports的多个副本(详细信息部分)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,询问用户输入数字,并根据输入内容执行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)

但这没用。我进行了搜索,但是我得到的所有解决方案都与带有保存的查询的Crystal Reports有关,这不是我的选择。

But that did not work. I searched, but all the solutions I got were related to Crystal Reports with Saved Queries which is not an option for me.

推荐答案

我终于做到了。

对于那些想知道如何做,或者想获得更好的 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-用Formulas替换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.

3-在Crystal Reports中,我使用了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.

这篇关于如何以编程方式生成Crystal Reports的多个副本(详细信息部分)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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