如何在没有紧密链接的数据库连接的情况下使用 Crystal Reports? [英] How to use Crystal Reports without a tightly-linked DB connection?

查看:12
本文介绍了如何在没有紧密链接的数据库连接的情况下使用 Crystal Reports?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习使用 Crystal Reports(使用 VB 2005).

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 want to display in the report.

我的数据库有很多外键,所以我试图在我的应用程序中呈现实际信息时保持理智的方式是向我的对象添加额外的成员,这些成员包含外键所代表的字符串(描述).喜欢:

My DB has a lot of foreign keys, so the way I've tried to stay sane with presenting actual information in my app is to add extra members to my objects that contain strings (descriptions) of what the foreign keys represent. Like:

Class AssetIdentifier

    Private ID_AssetIdentifier As Integer
    Private AssetID As Integer
    Private IdentifierTypeID As Integer
    Private IdentifierType As String
    Private IdentifierText As String

    ...

这里,IdentifierTypeID 是一个外键,我在另一个表中查找该值并将其放在 IdentifierType 中.这样我就可以在对象中直接添加文本描述,并且可以将它与其他东西一起随身携带.

Here, IdentifierTypeID is a foreign key, and I look up the value in a different table and place it in IdentifierType. That way I have the text description right in the object and I can carry it around with the other stuff.

那么,关于我的 Crystal Reports 问题.

So, on to my Crystal Reports question.

Crystal Reports 似乎可以很容易地连接到特定表中的记录(尤其是使用 Experts),但这就是你所得到的.

Crystal Reports seems to make it straightforward to hook up to records in a particular table (especially with the Experts), but that's all you get.

理想情况下,我想列出我的课程,例如

Ideally, I'd like to make a list of my classes, like

Dim assetIdentifiers as New List(Of AssetIdentifier)

并将其传递给 Crystal Report,而不是与特定数据库进行紧密链接,为我完成了大部分工作,但让我处理它不做的部分.到目前为止,我能看到的最接近的是 ADO.NET 数据集,但即便如此,它似乎也相去甚远.我自己已经很好地处理了查询:我有各种基于查询返回 List(Of What) 的函数.

and pass that to a Crystal Report instead of doing a tight link to a particular DB, have most of the work done for me but leaving me to work around the part that it doesn't do. The closest I can see so far is an ADO.NET dataset, but even that seems far removed. I'm already handling queries myself fine: I have all kinds of functions that return List(Of Whatever) based on queries.

有没有简单的方法可以做到这一点?

Is there an easy way to do this?

提前致谢!

更新:好的,我在这里找到了一些东西:

UPDATE: OK, I found something here:

http://msdn.microsoft.com/en-us/library/ms227595(VS.80).aspx

但它似乎只为 Web 项目或 Web 应用程序提供此功能.如果我想集成到一个独立的应用程序中,我会不走运吗?

but it only appears to give this capability for web projects or web applications. Am I out of luck if I want to integrate into a standalone application?

推荐答案

按照您发布的链接中的说明创建股票对象,并按照他们的指定创建报告 (StockObjectsReport).在这个简化的示例中,我只是将报表查看器 (crystalReportViewer1) 添加到表单 (Form1),然后在 Form_Load 事件中使用以下代码.

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;

这应该使用 Windows 窗体中 stock 对象的 3 个值填充您的报告.

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

对不起,我刚刚意识到您的问题是在 VB 中,但我的示例是在 C# 中.你应该得到一般的想法.:)

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

这篇关于如何在没有紧密链接的数据库连接的情况下使用 Crystal Reports?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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