简体   繁体   English

SSRS通过报告vb代码访问内置函数

[英]SSRS access built-in functions from report vb code

I'm working on create a multilingual SSRS report for SQL Server 2008R2. 我正在为SQL Server 2008R2创建多语言SSRS报告。 To do that without external code and only get translation from DB, I need to use Lookup() built-in function in the section code of the report. 为此,无需外部代码,仅从数据库获取翻译,我需要在报表的部分代码中使用Lookup()内置函数。
I have the following expression for textbox: 我的文本框具有以下表达式:

=LOOKUP("Rpt_0_Hello", Fields!Token.Value, Fields!Translation.Value, "DS_Translation")

The goal is to reduce the complexity of expression for the textbox translation. 目的是降低文本框翻译的表达复杂性。 I would like to get to the expression: 我想表达一下:

=Code.TrasT("Rpt_0_Hello")

I try to write a VB function like this: 我尝试编写这样的VB函数:

Public Function TransT( Token as String )
   Lookup( Token
          ,Report.Fields!Token.Value
          ,Report.Fields!Translation.Value
          ,"DS_Translation")
End Function

This code generate an error of "[BC30451]'Lookup' is not declared.". 此代码生成错误“未声明[BC30451]'Lookup'”。 I found on the web to use "Report" object to get Report element like Fields. 我在网上发现使用“报表”对象来获取报表元素,例如“字段”。
Is there a way to reference "Lookup()"? 有没有办法引用“ Lookup()”?

I think you are referring to the SSRS lookup function. 我认为您指的是SSRS查找功能。 You can;t use this directly in a Report Code function (as far as I know). 据我所知,您不能在报表代码功能中直接使用此功能。

However, what you probably want to do is just use the lookup function to get your translation from a dataset called 'DSTranslation'. 但是,您可能只想使用lookup函数从名为“ DSTranslation”的数据集中获取翻译。 If this is correct them simply set the expression of the textbox (or whatever) to the lookup function. 如果这是正确的,则只需将文本框(或其他内容)的表达式设置为查找函数。

So your textbox expression would just be 所以您的文本框表达式就是

=LOOKUP(Fields!Token.Value, Fields!Token.Value, Fields!Translation.Value, "DS_Translation")

This assumes both datasets have a field called Token 假设两个数据集都有一个名为Token的字段

If I've misunderstood then edit your question and explain what you are trying to do in a bit more detail and what data you have in your datasets. 如果我误解了,请编辑您的问题,并详细解释您要做什么以及数据集中的数据。

在自定义代码中无法调用Lookup()函数。

I found an answer to the goal of complexity reduction in the translation. 我找到了降低翻译复杂性目标的答案。 This not resolve the question but it's a workaround for minimize the work on multilingual report preparation. 这不能解决问题,但这是一种解决方法,可以最大程度地减少多语言报告准备工作。 You can use report variable as intermediate expression for the element to translate. 您可以将report变量用作元素翻译的中间表达式。 If you define a variable for any element to translate like this: 如果为任何要定义的变量定义一个变量,如下所示:

V_Hello=LOOKUP("Rpt_0_Hello", Fields!Token.Value, Fields!Translation.Value, "DS_Translation")

You now can use the following expression on textbox: 现在,您可以在文本框中使用以下表达式:

=Variables!V_Hello.Value

It's not direct and short like the solution of the question, but if you respect naming you can automate the insertion of this variables into the report XML file .rpt (this is a future problem). 它不像问题的解决方案那样直接和简短,但是如果您尊重命名,则可以自动将此变量插入到报表XML文件.rpt中(这是未来的问题)。
With this you kill two birds with one stone because you simplify expression and evaluate the expression once. 这样一来,您可以用一块石头杀死两只鸟,因为您可以简化表情并一次评估表情。 This may be useful on complex report. 这对于复杂的报告可能很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM