I am trying to load a csv file which is made up of just two rows. The first row lists a descriptor and the second row, the values. Example:
Date,Name,Age
1/1/2016,John,25
Ive created a data flow which reads this file in as a single column, then using a script transformation, reads each row from the file, splitting the values into two string arrays (firstRow and secondRow). Then it loops through each item in the string arrays writing the descriptor and value to two output values. The issue I have is that the Input0_processInput method runs twice for each row, duplicating the output in the database. As I am consuming all the rows at once and looping through them in the first iteration, the second time it runs before it sets the Input0Buffer.EndOfRowset to true, duplicates the values. Is there anyway to stop the processing after the first iteration?
Here is the code that allows me to read each row and match the column descriptors with the corresponding values:
int RowNumber = 0; string[] FirstRow; string[] SecondRow; bool filecompleted = false; /// <summary> /// </summary> /// <param name="Row">The row that is currently passing through the component</param> public override void Input0_ProcessInputRow(Input0Buffer Row) { if (RowNumber == 1) { FirstRow = Row.InputValueColumn.ToString().Split(new char[] { ',' }, StringSplitOptions.None); } else { SecondRow = Row.InputValueColumn.ToString().Split(new char[] { ',' }, StringSplitOptions.None); } } public override void Input0_ProcessInput(Input0Buffer Buffer) { while (Buffer.NextRow()) { RowNumber = RowNumber + 1; Input0_ProcessInputRow(Buffer); } // Counter var used the loop through the string array int i = 0; // Looping through string array with description names while (i < FirstRow.Length) { // Start a new row in the output Output0Buffer.AddRow(); // This is the splitted column. Take the [n] element from the array // and put it in the new column. Output0Buffer.OutputDescription = FirstRow[i]; Output0Buffer.OutputValue = SecondRow[i]; // Increase counter to go the next value i++; } if (Buffer.EndOfRowset()) { Output0Buffer.SetEndOfRowset(); } }