问题描述
不能在 sql Data Tools 脚本中应用相等性。
目的:建立一个变量,在不需要做任何事情时作为优雅退出使用
"Operator '==' cannot be applied to operands of type 'bool'"
Only assignment,call,increment,decrment,await,and new object expressions can be uses as statement
代码:
String recfil=Dts.Variables["User::FolderPath"].Value.ToString() + Dts.Variables["User::RecfileName"0.Value.ToString();
int recfilExists=Convert.ToInt32(File.Exists(recfil));
bool goodRun = irecfilExists.Equals(1)
bool norun = irecfilExists.Equals(0)
if (goodRun)
{
Dts.Variables["User::nothingTodo"].Value == goodRun;
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
Dts.Variables["User::nothingTodo"].Value == norun;
Dts.TaskResult = (int)ScriptResults.Failure;
}
解决方法
虽然绝对不是最佳答案,
if (goodRun || noRun)
{
if (goodRun)
{
Dts.Variables["User::FileCount"].Value = 1;
}
else
{
Dts.Variables["User::FileCount"].Value = 0;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
Dts.TaskResult = (int)ScriptResults.Failure;
}
然后在控制流中,在 Success 上添加选择函数,将文件计数引用为 1 或 0。如果没有文件,请正常退出,否则执行控制流程。