SSRS 2008的定制组装

时间:2011-05-09 19:00:26

标签: ssrs-2008

我正在尝试将多个报表中的嵌入式代码整合到自定义程序集中。我在VS 2008中创建了一个名为BalancingReportsLibrary的C#Library项目。这是我的库中的代码:

使用System; 使用System.Collections.Generic; 使用System.Linq; 使用System.Text;

namespace BalancingReportsLibrary {     公共课平衡     {         public string ComingledPounds(string CoPounds)         {             if(CoPounds == null || CoPounds ==“”)             {                 返回“”;             }

        //Column One
        int index = CoPounds.IndexOf(";");
        int length = CoPounds.Length;

        if (index > 0)
        {
            string CoPounds1 = CoPounds.Substring(0, index);
            return CoPounds1;
        }

        //There was just one comingled pound, so just return the value that was passed in
        return CoPounds;

    }

我已构建此解决方案并将DLL放在此路径中: C:\ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ PrivateAssemblies

我创建了一个包含报告的报告项目。在报告>属性>参考文献下,我在程序集下选择了我的DLL。我在表单上有一个文本框引用类,如下所示: = BalancingReportsLibrary.Balancing.ComingledPounds(LAST(字段!ComingledGroup.Value))

尝试预览报告时出现以下错误: “表达式的值失败。对非共享成员的引用需要对象引用。”

如何解决此问题?

1 个答案:

答案 0 :(得分:1)

如果您实际上不需要实例化Balancing类,但只想调用ComingledPounds方法,那么将其设置为静态,如下所示:

namespace BalancingReportsLibrary 
{ 
    public class Balancing 
    {
        public static string ComingledPounds(string CoPounds) 
        {
            if (CoPounds == null || CoPounds == "") 
                return "";

            //Column One
            int index = CoPounds.IndexOf(";");
            int length = CoPounds.Length;

            if (index > 0) {
                string CoPounds1 = CoPounds.Substring(0, index);
                return CoPounds1;
            }

            //There was just one comingled pound, so just return the value that was passed in
            return CoPounds;
        }
    }
}