1  /  1  页   1 跳转 查看:5667

SSRS: Create and Call a Custom Assembly

SSRS: Create and Call a Custom Assembly

最近做报表,在网上搜了些文章,贴在这里,希望这里越来越旺

SQL Server Reporting Services: Create and Call a Custom Assembly
In one of my previous articles I explained how to use embedded code in SQL Server Reporting Services. The possibility to add embedded code to a report, is a very powerfull feature to add some custom functionality to your report.
But sometimes it might be necessary to add some custom functionality that is too complicated for embedded code to handle efficiently, or you need to access the same function from multiple reports, or you would like to write you code in C#...
In one of these cases you should develop a custom assembly to call from your report.

Let’s start with a simple example and develop a function PercentageToColor() to return a color based on a numeric value representing a percentage.
namespace MyAssembly
{

public
class
Colors

{


public
string PercentageToColor(double percentage)

{


string returnValue = string.Empty;


if (percentage < 20)

{


returnValue =
"red";

}


else
if (percentage < 80)

{


returnValue =
"blue";

}


else

{


returnValue =
"green";

}


return returnValue;

}


}

}
Once you’ve compiled your class you need to copy the resulting assembly to the directory in which it is accessible from within your report:
·        To use it in the report designer, you need to copy it to:

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies

·        To make it available for reports that have been deployed to the report server, you need to copy it to:

C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin

Before you can access your custom assembly you have to reference the assembly: Open the report properties (Menu: Report – Report Properties) and select the References tab.
Browse to your assembly and define a Class Name and an Instance Name. (The Class Name and the Instance Name or only for non-static methods). Make sure to prefix your class name with the assembly name.
Now you can call the methods in your assembly from your report, using an expression:
·        To call a static method: = <AssemblyName>.<ClassName>.<StaticMethodName>
·        To call an instance method: =Code.<InstanceName>.<;PublicMethodName>
So in our example this would be: =Code.TestColor.PercentageToColor(Fields!Percentage.Value)
That's it! You've just created and called a custom assembly from your report...

In one of my future articles I will explain how to pass parameters to the class constructor and I will also tell something about SSRS and .Net Permissions...


原文在这里
http://geekswithblogs.net/davyknuysen/archive/2007/03/26/109901.aspx
最后编辑拓狼 最后编辑于 2007-06-13 10:06:26
 

回复: SSRS: Create and Call a Custom Assembly

报告班主任,上面那贴中冒出个小家伙在笑话俺。

还有个小小的bug,帖子编辑完后,下面的按钮应该叫“发布...”什么的,现在显示的是“编辑帖子”。
俺们脑子慢,愣看了3分钟才醒过闷儿来。俺们兄弟批评俺:"就这脑袋,还编程?怯!"
 

回复: SSRS: Create and Call a Custom Assembly

楼主在发贴的时候,左边有个这样的图,选中图中已选中的那个复选框就OK啦


 附件: 您所在的用户组无法下载或查看附件
虽有智慧,不如乘势;虽有鎡基,不如待时。
君子学以聚之,问以辨之,宽以居之,仁以行之。
独学而无友,则孤陋而寡闻。
 

回复: SSRS: Create and Call a Custom Assembly

顶...
谢谢楼主。:lol
 

回复: SSRS: Create and Call a Custom Assembly

支持,希望以后能有更多更好的文章。谢谢ww2002!
 

回复:SSRS: Create and Call a Custom Assembly

可惜SSIS2005的EXPRESSION不能扩展,只能在自定义组件和自定义脚本里使用自定义托管代码
 
1  /  1  页   1 跳转

版权所有 微软BI开拓者 

Powered by Discuz!NT 2.1.202    Copyright © 2001-2012 Comsenz Inc.
Processed in 0.4375168 second(s) , 2 queries.
返顶部