'Extracting header row from csv and loading into SQL table using C# Script in SSIS
I am currently working on a project within SSIS and require some assistance.
What I'm trying to achieve:
- Extract CSV column headers (do not extract the data, only the headers) dynamically using script task and load the headers into a specified table.
What is currently happening:
- The CSV file is read, the Column headers are extracted, however the headers are loaded into the specified table for each row in the file. For example 2000 rows in the source file means the headers are loaded 2000 times.
Here is the code, any assistance would be appreciated...I have a workaround using SQL but I would quite like to get the Script Task working for the future.
while (!csvReader.EndOfData)
{
string[] fieldData = csvReader.ReadFields();
//Making empty value as null
for (int i = 0; i < 1; i++)
{
if (colFields[i] == "")
{
colFields[i] = null;
}
}
csvData.Rows.Add(colFields);
CsvRowCount = csvData.Rows.Count;
}
csvReader.Close();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
