简体   繁体   中英

SSRS access built-in functions from report vb code

I'm working on create a multilingual SSRS report for SQL Server 2008R2. 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.
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:

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.". I found on the web to use "Report" object to get Report element like Fields.
Is there a way to reference "Lookup()"?

I think you are referring to the SSRS lookup function. 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'. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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