为什么在SSIS脚本中出现以下错误?

为什么在SSIS脚本中出现以下错误?,ssis,Ssis,我有一个简单的脚本: public void Main() { // TODO: Add your code here Dts.TaskResult = (int)ScriptResults.Success; //MYCode Variables varCollection = null; string DestinationRoot = varCollection("User

我有一个简单的脚本:

 public void Main()
    {
        // TODO: Add your code here
        Dts.TaskResult = (int)ScriptResults.Success;


        //MYCode

        Variables varCollection = null;
     

        string DestinationRoot = varCollection("User::DestinationRoot").Value.ToString();
        int MonthStartPosition = Convert.ToInt32(varCollection("User::MonthStartPosition").Value);
        int MonthLength = Convert.ToInt32(varCollection("User::MonthLength").Value);
        int MonthValue = 0;
        string MonthNameFormat = varCollection("User::MonthNameFormat").Value.ToString();
        string FolderName = string.Empty;
        string MonthwiseDirectory = string.Empty;

        if (MonthStartPosition > 0 && MonthLength > 0)
        {
            MonthValue = Convert.ToInt32(FileName.Substring(MonthStartPosition - 1, MonthLength));
        }

        if (FileName.Length > 0 && MonthValue > 0)
        {
            FolderName = new DateTime(1, MonthValue, 1).ToString(MonthNameFormat);
        }

        MonthwiseDirectory = System.IO.Path.Combine(DestinationRoot, FolderName);

        if (!System.IO.Directory.Exists(MonthwiseDirectory))
        {
            System.IO.Directory.CreateDirectory(MonthwiseDirectory);
        }

        varCollection("User::DestinationFolder").Value = MonthwiseDirectory;

//Error 1 : also getting error here like 'varCollection' is a 'variable' but is used like a 'method'   

        Dts.TaskResult = Dts.Results.Success; //Error 2 
    }
但它会产生如下错误:

错误1:“varCollection”是“变量”,但与“方法”一样使用

错误2:“Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel”不包含“Results”的定义,并且找不到接受类型为“Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel”的第一个参数的扩展方法“Results”(是否缺少using指令或程序集引用?)C:\Users\AppData\Local\Temp\SSIS\dfac06a62ee9472bac783737af4957de\ScriptMain.cs 91 34 st_7c1dde41280d4efc996c50fead62bfa9


根据MSDN页面,ScriptObjectModel类没有名为“Results”的属性


您需要发布代码以进行全面诊断。

我得到了错误1的答案 当我使用C时,需要分配如下值:


Dts.Variables[“DestinationFolder”]。Value=MonthwiseDirectory

首先,关于如何使用堆栈溢出的两件事

  • 请不要发布新的问题,如果你可以直接问回答你问题的人如何在C#中这样做。此外,请务必提及您在发布的问题中使用的版本

  • 请不要在回答中张贴您的问题

  • 无论如何,这里是我发布的VB.NET代码的C代码。我还更新了你另一个问题的原始答案,将C代码包括在内


    这行在脚本任务中吗?它是
    Main
    块中唯一的一行吗?您可以复制整个脚本来说明这一点吗?Dts.TaskResult=Dts.Results.Success;上面的代码是用Vb.net编写的,我想把它转换成c#
    public void Main()
    {
        Variables varCollection = null;
        Dts.VariableDispenser.LockForRead("User::SourceFilePath");
        Dts.VariableDispenser.LockForRead("User::DestinationRoot");
        Dts.VariableDispenser.LockForRead("User::MonthStartPosition");
        Dts.VariableDispenser.LockForRead("User::MonthLength");
        Dts.VariableDispenser.LockForRead("User::MonthNameFormat");
        Dts.VariableDispenser.LockForWrite("User::DestinationFolder");
        Dts.VariableDispenser.GetVariables(ref varCollection);
    
        string SourceFilePath = varCollection["User::SourceFilePath"].Value.ToString();
        string FileName = SourceFilePath.Substring(SourceFilePath.LastIndexOf('\\') + 1);
        string DestinationRoot = varCollection["User::DestinationRoot"].Value.ToString();
        int MonthStartPosition = Convert.ToInt32(varCollection["User::MonthStartPosition"].Value);
        int MonthLength = Convert.ToInt32(varCollection["User::MonthLength"].Value);
        int MonthValue = 0;
        string MonthNameFormat = varCollection["User::MonthNameFormat"].Value.ToString();
        string FolderName = string.Empty;
        string MonthwiseDirectory = string.Empty;
    
        if (MonthStartPosition > 0 && MonthLength > 0)
        {
            MonthValue = Convert.ToInt32(FileName.Substring(MonthStartPosition - 1, MonthLength));
        }
    
        if (FileName.Length > 0 && MonthValue > 0)
        {
            FolderName = new DateTime(1, MonthValue, 1).ToString(MonthNameFormat);
        }
    
        MonthwiseDirectory = System.IO.Path.Combine(DestinationRoot, FolderName);
    
        if (!System.IO.Directory.Exists(MonthwiseDirectory))
        {
            System.IO.Directory.CreateDirectory(MonthwiseDirectory);
        }
    
        varCollection["User::DestinationFolder"].Value = MonthwiseDirectory;
    
        Dts.TaskResult = (int)ScriptResults.Success;
    }