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

查看:157
本文介绍了如何在没有紧密连接的DB连接的情况下使用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.

所以,对于我的水晶报表问题。

So, on to my Crystal Reports question.

水晶报表似乎可以直接连接到特定表中的记录(尤其是与专家),但这是你得到的。

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而不是紧密链接到特定的DB,大部分的工作为我做,但让我工作周围的部分,它不做。最近我可以看到到目前为止一个ADO.NET数据集,但即使这似乎远去。我已经处理查询我自己罚款:我有各种函数返回基于查询的List(Of Whatever)。

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?

提前感谢!

更新:

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. :)

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

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