我如何可以检索一个水晶报表使用的SQL SELECT语句? [英] How can I retrieve the SQL SELECT statement used in an Crystal Report?

查看:224
本文介绍了我如何可以检索一个水晶报表使用的SQL SELECT语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作在C#中的程序,让我们的用户运行,查看和导出了一批水晶报表。这些报告是利用Crystal Reports 2008的图形用户界面进行。其中一个这样做的主要原因是为了让我们preserve超链接时,水晶报表导出为PDF。我的程序通过导出到RTF,那么RTF转换为PDF做到这一点。如果在转换为PDF时有人知道preserving超链接不太令人费解的方法,我很想听到它,但是这不是我现在的问题。

I am currently working on a program in C# that allows our users to run, view and export a batch of Crystal Reports. The reports were made using the Crystal Reports 2008 GUI. One of the main reasons for doing this is to allow us to preserve hyperlinks when the Crystal Report is exported to PDF. My program does this by exporting to rtf, then converting the rtf to a pdf. If anyone knows of a less convoluted method of preserving hyperlinks when converting to PDf I'd love to hear it, but that's not my current question.

我已经做了很多关于如何优化我的程序,使出口采取尽可能少的时间尽可能的测试。从我所看到的,具有用于数据的应用程序的查询,然后结合的结果集的水晶报表是目前为止最快的方法。我的问题是,我不能硬$ C C查询$进入程序,他们需要从Crystal报表本身retreived。

I have done a lot of tests on how to optimize my program to make the export take as little time as possible. From what I've seen, having the application query for the data, then binding the resultset to the Crystal Report is by far the fastest method. My problem is that I can't hard-code the queries into the program, they need to be retreived from the Crystal Report itself.

在水晶报表2008年,有一个名为显示SQL查询下的数据库菜单中的选项。这带来了用于给定报表的SQL查询窗口。这正是我需要让我的手从我的应用程序。我已经加载的水晶报表并且,在调试时,走过的的ReportDocument对象试图找到查询,但没有运气。

In Crystal Reports 2008, there is an option called "Show SQL Query" under the Database menu. This brings up a window with the SQL query used for the given report. This is exactly what I need to get my hands on from within my application. I've loaded a crystal report and, while debugging, traversed the ReportDocument object trying to find the query, but no luck.

所以,我的问题是;有没有什么方法可以,让我拉出来使用给定的水晶报表的查询?

So, my question is; is there any method available that would allow me to pull out the query used by a given Crystal Report?

推荐答案

好了,所以dotjoe给了我一切,我需要工作,这一点的提示。下面code可以用来拉从一个水晶报表命令文本。

Alright, so dotjoe gave me all of the hints that I needed to work this out. The following code can be used to pull the command text from a crystal report.

public string getCommandText(ReportDocument rd)
{
    if (!rd.IsLoaded)
        throw new ArgumentException("Please ensure that the reportDocument has been loaded before being passed to getCommandText");
    PropertyInfo pi = rd.Database.Tables.GetType().GetProperty("RasTables", BindingFlags.NonPublic | BindingFlags.Instance);
    return ((dynamic)pi.GetValue(rd.Database.Tables, pi.GetIndexParameters()))[0].CommandText;
}

这看起来有点凌乱,但它使某种感觉,当你开始通过它涉水。基本上,它使用反射来获取CommandText属性的值,其中投入了,让过去在的ReportDocument的动态特性有点动态。

It looks a bit messy, but it makes some sort of sense when you start wading through it. Basically, it uses reflection to get the value of the CommandText property, with a little dynamics thrown in to get past the dynamic properties in the ReportDocument.

这是拉动命令文本适合我,但我已经没有时间做的code任何测试。我敢肯定,我会做一些调整,一旦我已经受够了这个工作的时间。我不知道与不使用SQL命令报告会发生什么。我要发表评论,一旦我测试过这进一步。

This is pulling the command text for me, but I have had no time to do any tests on the code. I'm sure I'll be making some tweaks once I've had the time to work with this. I have no clue what happens with reports that do not use "SQL Commands". I'll post a comment once I've tested this further.

  • 斯科特

P.S。这需要你引用标准反射/动态库,以及下面的Crystal报表库:

P.S. This requires that you reference the standard reflection/dynamic libraries, as well as the following Crystal Report libraries:

crystaldecisions.reportappserver.datadefmodel

crystaldecisions.reportappserver.datadefmodel

crystaldecisions.crystalreports.engine

crystaldecisions.crystalreports.engine

crystaldecisions.shared

crystaldecisions.shared

这篇关于我如何可以检索一个水晶报表使用的SQL SELECT语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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