0

I am having the index was out of bounds error for the following script. I have 1 input column and 11 output columns added to the SSIS Script component. The data types for all of them are string. Not sure where I am going wrong. Thanks in Advance.

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    Dim strRow As String
    Dim strColSeperator As String
    Dim rowValues As String()
    strRow = Row.Line.ToString()
    If strRow.Contains("-") Then
        strColSeperator = ("-")
    ElseIf strRow.Contains(";") Then
        strColSeperator = ";"
    End If

    rowValues = Row.Line.Split(CChar(strColSeperator))
    Row.Invoices = rowValues.GetValue(0).ToString()
    Row.Detail = rowValues.GetValue(1).ToString()
    Row.Date = rowValues.GetValue(2).ToString()
    Row.Something1 = rowValues.GetValue(3).ToString()
    Row.Something2 = rowValues.GetValue(4).ToString()
    Row.SomeNumber = rowValues.GetValue(5).ToString()
    Row.CustomerName = rowValues.GetValue(6).ToString()
    Row.InvoiceNumber = rowValues.GetValue(7).ToString()
    Row.InvoiceNumber2 = rowValues.GetValue(8).ToString()
    Row.InvoiceNumber3 = rowValues.GetValue(9).ToString()
    Row.InvoiceNumber4 = rowValues.GetValue(10).ToString()

End Sub
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
rvphx
  • 2,324
  • 6
  • 40
  • 69
  • Dollars to dumplings you've got skunky data in there. On your Script transformation, add an second output (Output 1) to catch the offending rows. Add a column to Output 1, column name Line matching the existing data type. Wrap the above code in a try/catch block. In the catch portion, add these two lines `Output1Buffer.AddRow()` and `Output1Buffer.Line = Row.Line` Direct those into file or add data viewer and see why it fails to split into expected size. – billinkc Jan 20 '12 at 20:13

1 Answers1

0
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) 
    Dim strRow As String 
    Dim strColSeperator As Char ' <== Char instead of string 
    Dim rowValues As String() 

    strRow = Row.Line.ToString() 
    If strRow.Contains("-") Then 
        strColSeperator = "-"c ' <== the 'c' denotes a Char literal
    ElseIf strRow.Contains(";") Then 
        strColSeperator = ";"c 
    End If 

    rowValues = strRow.Split(strColSeperator) ' <== Now CChar is obsolete
    MsgBox("rowValues length = " & rowValues.Length) ' <== Check to see if it's really as long as expected!
    Row.Invoices = rowValues(0) ' <== Use the array indexer instead of GetValue and ToString
    Row.Detail = rowValues(1) 
    Row.Date = rowValues(2) 
    Row.Something1 = rowValues(3)
    Row.Something2 = rowValues(4)
    Row.SomeNumber = rowValues(5)
    Row.CustomerName = rowValues(6)
    Row.InvoiceNumber = rowValues(7)
    Row.InvoiceNumber2 = rowValues(8)
    Row.InvoiceNumber3 = rowValues(9)
    Row.InvoiceNumber4 = rowValues(10)
End Sub 
Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • Oliver, I ran the code that you provided. It goes on for a while displaying mostly 11 and 12's on the message box(approx 14 times). After the 14 clicks comes 7 and after that it fails again with the same issue. I checked my data and its the same for the first 20 lines or so. Any idea what might be going on? – rvphx Jan 20 '12 at 22:30
  • 2
    Try with displaying `strRow`, in order to see what it really contains. My guess is that you are using a wrong separator. What if the separator is ";" and your row contains negative values with a minus sign ("-")? – Olivier Jacot-Descombes Jan 20 '12 at 22:38