を使用してUser::PrevMonth
データ型の変数に値を代入しようとしていますが、値が設定されていません。プロパティ ペインで変数に値が設定されていません。String
Script Task
Variables
スクリプト タスクがControl Flowに設定されました。スクリプト タスクのプロパティで、2 つの変数を として設定しましReadWriteVariables
た。他の変数は正常に機能しているようで、次のように宣言されていますInt32
これが私のスクリプトタスクコードです:
/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace ST_7206cd3a4d734228b8d6860bdb6a59c9.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public void Main()
{
//This will get the year as an int (e.g. 2013)
DateTime dLastYear = DateTime.Today.AddYears(-1);
int iLastYear = dLastYear.Year;
//This will get the month as an str (e.g. 04)
DateTime dLastMonth = DateTime.Today.AddMonths(-1);
string sLastMonth = dLastMonth.ToString("MM");
//Assign variables back to SSIS package
Dts.Variables["User::PrevMonth"].Value = sLastMonth;
Dts.Variables["User::Year"].Value = iLastYear;
//Return package success
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
String データ型の変数は、パッケージの実行が成功した後、その値を変更しません。これは本当に私を悩ませています。すべてをチェックしたような気がします。
誰かが私が欠けているものを見つけることができますか? それは本当にばかげた/明白なものだと思います。
アップデート:
Message Box
内部で変数値を表示するために使用しましScript Task
たが、正しい出力が表示されています。