我需要一些帮助.
我从oledb源导入.csv文件中的一些数据.我不希望标题在目标中出现两次.如果我取消选中"第一个数据行中的列名"属性,则在第一次执行时也不会填充标题.
截至目前的输出.
Col1,Col2
A,B
Col1,Col2
C,D
Run Code Online (Sandbox Code Playgroud)
如何以这样的方式运行包:如果文件为空,则插入标头.然后,如果再次执行,则不包括标题,只包括数据.
有一个类似的线程,但无法应用解决方案如何使用表达式来获取目标本身的行数.很久以前,所以我创造了一个新的.
非常感谢您的帮助.
-Akshay
也许我错过了一些东西,但这对我有用.我没有使用ColumnNamesInFirstDataRow的只读问题
我创建了一个名为的包级变量AddHeader,类型为Boolean并将其设置为True.我添加了一个名为FFCM的平面文件连接管理器,并将其配置为使用2列HeadCount(int),AddHeader(boolean)的CSV输出.在Connection Manager的属性中,我为属性'ColumnNamesInFirstDataRow'添加了一个Expression,并为其赋值为@[User::AddHeader]

我添加了一个脚本任务来测试文件的大小.它具有对Variable AddHeader的读/写访问权限.然后我使用此脚本来确定文件是否为空.如果你的"空"的定义是它有一个标题行,那么我会调整if检查中的逻辑以匹配该长度.
public void Main()
{
string path = Dts.Connections["FFCM"].ConnectionString;
System.IO.FileInfo stats = null;
try
{
stats = new System.IO.FileInfo(path);
// checking length isn't bulletproof based on how the disk is configured
// but should be good enough
// http://stackoverflow.com/questions/3750590/get-size-of-file-on-disk
if (stats != null && stats.Length != 0)
{
this.Dts.Variables["AddHeader"].Value = false;
}
}
catch
{
// no harm, no foul
}
Dts.TaskResult = (int)ScriptResults.Success;
}
Run Code Online (Sandbox Code Playgroud)
我循环了两次,以确保我生成追加方案

我删除了我的文件并运行了包,只有一个标题.
