SSRS and accessing C# methods
开发者_StackOverflow社区Would like to know if methods need to be static in a C# assemble to be access from SSRS?
No, you can use both public methods and static methods in a c# class library and reference them from your SSRS report.
You do need to add static methods in a different way than your public instance methods though. You should check out this MS article on custom code use in SSRS. Here is the gist of how to add a static method:
The Classes section is only for instance-based members. It is not for static members. Static (also referred to as "shared" in some of our Reporting Services documentation) means that the member is available to every instance of the class and every instance uses the same storage location. Static members are declared by using the shared keyword in Microsoft Visual Basic and the static keyword in C#. This can be a bit confusing. What this means is, if your custom assembly contains instance members that you need to access, you will have to specify the class name and instance name in the Classes section. Because the method I will be calling from Reporting Services was defined as static by using the shared keyword in Visual Basic, I'll use the References section instead of the Classes section.
So, if you want to do an instance method, make sure to add the refrence, but also specify a "Class" and "Instance name" in the Classes section of Report Properties for every method you need. Then call them using an expression of =Code. Like so:
=Code.InstanceName.Method
Hope that will help you out.
精彩评论