ソーススクリプトコンポーネントのC#ソリューション(私はそれをチェックしていませんが、動作すると思います)があります。
splitを使用してヘッダーを配列に読み込みます。
各データ行に対して、同じ分割関数を使用し、ヘッダー値を使用して列をチェックし、rowvalを使用して出力を設定します。
すべての出力列を出力領域に配置する必要があります。
存在しないすべての列は、終了時にヌル値を持ちます。
public override void CreateNewOutputRows()
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(@"[filepath and name]"))
{
while (!sr.EndOfStream)
{
string FullText = sr.ReadToEnd().ToString();
string[] rows = FullText.Split('\n');
//Get header values
string[] header = rows[0].Split(',');
for (int i = 1; i < rows.Length - 1; i++)
{
string[] rowVals = rows[i].Split(',');
for (int j = 0; j < rowVals.Length - 1; j++)
{
Output0Buffer.AddRow();
//Deal with each known header name
switch (header[j])
{
case "Field 1 Name": //this is where you use known column names
Output0Buffer.FieldOneName = rowVals[j]; //Cast if not string
break;
case "Field 2 Name":
Output0Buffer.FieldTwoName = rowVals[j]; //Cast if not string
break;
//continue this pattern for all column names
}
}
}
}
}
}
どのようにCSVを1行ずつ読みましたか?あなたはどのようにインサートをしましたか?どのコンポーネントを使用しましたか? –
私はファイルを読むためにcsvreaderを使いました。挿入はsqlcommandオブジェクトを介して行われました。 –
あなたがcsvreaderと言うときは、フラットファイルソースを意味しますか、これはいくつかの顧客コンポーネントです。 sqlcommandオブジェクトは、行単位の挿入を行います。これをoledbデスティネーションに変更すると、フラットファイルソース –