如何使用脚本任务
从ssis中的另一个文件中读取文件名我尝试了波纹管代码,但我收到单个文件 我的要求是一次读取一个文件并将数据加载到表中。
public void Main()
{
String filename = Dts.Variables["filename"].Value.ToString();
using (System.IO.StreamReader rdr = new System.IO.StreamReader(filename))
{
Dts.Variables["User::filename"].Value = rdr.ReadLine();
}
Dts.TaskResult = (int)ScriptResults.Success;
}
class for setting the
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
}
}
答案 0 :(得分:0)
public class ScriptMain
{
public void Main()
{
const string FILE_PATTERN = ""(your file pattern);
string Folder;
string[] Files;
Folder = Dts.Variables["Folder"].Value.ToString();
Files = Directory.GetFiles(Folder, FILE_PATTERN);
Dts.Variables["Files"].Value = Files;
Dts.TaskResult = (int)ScriptResults.Success;
}
}
and also you can read this for : http://www.msbiguide.com/2013/09/looping-through-files-using-foreach-loop-container-in-ssis-2008-r2/