我有一个.csv文件目录,我想加载到数据库中,每个表的标题都是.csv标题。
我有一个foreach循环来处理这个问题。 使用脚本操作定义和修改的当前目录,当前文件和tblName的变量。
我的foreach循环的最后一个命令更新了当前的File变量,但它似乎没有刷新平面文件连接,因为调试失败并显示错误,指出在前一个csv中找到的列是预期的但在数据源中找不到(是目录中的下一个csv
这里是在for / each循环结束时更新var的代码。
int pos = (int)Dts.Variables["User::pos"].Value;
string dirPath = (string)Dts.Variables["User::sourceFolder"].Value;
pos++;
Dts.Variables["User::pos"].Value = pos;
//object ffConnection = Dts.Connections["CSV FILE"].AcquireConnection(Dts.Transaction);
//string filePath = (string)ffConnection;
//MessageBox.Show(ffConnection.ToString());
//Dts.Connections["CSV FILE"].ReleaseConnection(ffConnection);
DirectoryInfo di = new DirectoryInfo(dirPath);
FileInfo[] diAr1 = di.GetFiles("*.csv");
FileInfo next;
string nextPath;
string tblName;
//MessageBox.Show(next.FullName);
if (diAr1.Length > 1){
next = diAr1[pos];
nextPath = next.FullName;
tblName = Path.GetFileNameWithoutExtension(nextPath);
Dts.Variables["User::CurrentFile"].Value = nextPath;
Dts.Variables["User::tblName"].Value = tblName;
MessageBox.Show("script's tblName: " + tblName);
MessageBox.Show("User::tblName: " + (string)Dts.Variables["User::tblName"].Value);
MessageBox.Show("User::CurrentFile: " + (string)Dts.Variables["User::CurrentFile"].Value);
}
Dts.TaskResult = (int)ScriptResults.Success;