无法以编程方式设置 Crystal Report 选择公式
首先,我受不了水晶!好吧,这就是我的心声...
现在,我们有一个为客户维护的旧 VB6 应用程序,它使用 Crystal Automation 库以编程方式更改一堆 中的记录选择公式Crystal Reports 8.5 报告。
有两份报告几乎完全相同。我最近不得不更改它们以添加另一个表中的另一个字段。当我将表添加到报告中时,虽然它在可视化设计器中添加了它,但它没有将其添加到 SQL 语句的 FROM 子句中。因此,我手动编辑了 SQL 语句以添加附加联接。 KO,效果很好。如果我在 Crystal 预览模式下运行报告,它们将完全按预期工作。
现在,用户可以在 VB 应用程序中测试更改。其中一份报告工作得很好而且很花花公子。然而,另一份报告未能按预期设置选择公式。
该代码使用函数PESetSelectionFormula
设置选择公式。我通过对变量的逐步检查来验证作为新选择公式传递到函数的字符串是否正确。对 PESetSelectionFormula
的调用似乎工作正常,并且返回值 1,这是我在任何地方都能找到的表明成功的值。 (另一个在代码中工作正常的报告也返回 1。)
但是,该报告失败并出现错误:错误代码:534 - 数据库 DLL 检测到错误。
SELECT ... FROM ...
WHERE
ORDER BY ...
如您所见,WHERE 子句为空,我想这就是数据库 DLL 对此语句进行 upchucking 的原因。我不明白为什么自动化库没有设置 WHERE 子句,即使对 PESetSelectionFormula
的调用传递了有效字符串并返回成功。我想也许是因为我在报告中手动编辑了 SQL 以添加它没有添加的表,但我在另一个几乎相同的报告中做了同样的事情,并且该报告工作正常。
任何人都知道为什么 PESetSelectionFormula
可能报告成功但实际上没有执行任何操作?
PS 我已经尝试过做一个数据库>从菜单中验证数据库,这表明报告都是最新的,根本没有帮助。
first, I can't stand Crystal! Okay, that's off my chest...
Now, we have an old VB6 app we maintain for a client, which uses the Crystal Automation library to programatically change the record selection formulas in a bunch of Crystal Reports 8.5 reports.
There are two reports which are ALMOST identical. I had to change them recently to add another field from another table. When I added the table in to the reports though, while it added it in the visual designer, it did not add it in the FROM clause of the SQL statement. So, I manually edited the SQL statement to add in the additional join. KO, works great. If i run the reports in Crystal preview mode, they work exactly as expected.
Now, the users went to test the changes from within the VB app. One of the reports works fine and dandy. The other report however, is failing to set the selection formula as expected.
The code sets the selection formulas using the function PESetSelectionFormula
. I verified that the string being passed in to the function as the new selection formula is correct via a step-through examination of the variables. The call to PESetSelectionFormula
seems to be working okay, and is returning a value of 1, which as near as I can find anywhere indicates success. (The other report, which is working fine from code is also returning 1.)
However, the report is failing with an error: Error Code: 534 - Error detected by database DLL.
The code, for debugging purposes dumps out the SQL string currently being used by the report. The SQL coming out of the report is:
SELECT ... FROM ...
WHERE
ORDER BY ...
As you can see, the WHERE clause is blank, which I would imagine is why the database DLL is upchucking on this statement. I don't understand why the automation library is not setting the WHERE clause even though the call to PESetSelectionFormula
is being passed a valid string and is returning success. I thought perhaps it was because I had manually edited the SQL in the report to add the table it wasn't adding, but I did the same thing in the other nearly identical report, and that one is working fine.
Anyone have any ideas why PESetSelectionFormula
might report success but not actually do anything?
P.S. I have already tried doing a Database > Verify Database from the menus, and that said the report was all up to date and did not help at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我从未使用过PESetSelectionFormula,但在导入可接受的数据时遇到了问题:
您的最终 SQL 查询是否使用任何不常见的函数,即 nz()? Crystal 并不总是能够识别 VB 函数,恕我直言。
您导入的数据中是否有任何空值会造成冲突?
收集数据后,您能否将其放入临时表中并告诉 Crystal 从该临时表中获取数据?如果您遇到#1 或#2 问题,这可能是一个很好的解决方法。
I've never used PESetSelectionFormula, but I have encountered problems importing otherwise acceptable data:
Does your final SQL query use any uncommon functions, i.e. nz()? Crystal doesn't always recognize VB functions, imho.
Do you have any null values in your imported data that are creating conflicts?
After gathering your data, can you put it into a temporary table and tell Crystal to pick up the data from that temp table? If you have issues with #1 or #2, this may be a good workaround.
在 CR 的某些版本中,PESetSelectionFormula 将新值附加到现有记录选择公式,在其他版本中,PESetSelectionFormula 使用新值替换现有记录选择公式。
我不记得此切换何时发生,但您应该很容易确定正在发生哪种行为。
In some versions of CR, the PESetSelectionFormula appends the new value to the existing record-selection formula, in other versions, PESetSelectionFormula replaces the existing record-selection formula with the new value.
I don't recall when this switch occurred, but it should be easy for you to determine which behavior is occurring.
好吧,这就是我鄙视 Crystal Reports 的典型原因。
我的老板度假回来,看了看,……什么都没做,现在可以了。
他向我展示了他所做的事情,并且他没有对报告进行任何更改或执行任何操作,只是与我采取的调试步骤相同,但现在它神奇地起作用了。
我真的不喜欢像这样自动停止和开始工作的软件。
感谢您的想法。
Okay, this is typical of why I just despise Crystal Reports.
My boss came back from vacation, and looked at it, ... did nothing, and now it works.
He showed me exactly what he did, and he didn't change or do anything to the report, just the same debugging steps I'd taken, but now it magically works.
I truly dislike software that just automagically stops and starts working like this.
Thanks for the ideas.