2012-01-20 25 views
0

我的索引超出了以下腳本的界限錯誤。我有1個輸入列和11個輸出列添加到SSIS腳本組件。所有這些數據類型都是字符串。不知道我哪裏錯了。 在此先感謝。索引在VB.NET腳本中出現了界限錯誤

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 
+0

美元餃子你已經在那裏了臭鼬數據。在您的腳本轉換中,添加第二個輸出(輸出1)以捕捉違規行。向輸出1添加一列,列名稱與現有數據類型匹配。將上面的代碼包裝在try/catch塊中。在catch部分中,添加這兩行'Output1Buffer.AddRow()'和'Output1Buffer.Line = Row.Line'將這些行引入文件或添加數據查看器,並查看爲什麼它無法分裂爲預期大小。 – billinkc

回答

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 
+0

奧利弗,我跑了你提供的代碼。它在信息框中大約顯示11個和12個(大約14次)。在14次點擊來到7之後,再次出現同樣的問題。我檢查了我的數據,前20行左右的數據也一樣。任何想法可能會發生什麼? – rvphx

+2

嘗試顯示'strRow',以查看它真正包含的內容。我的猜測是你正在使用錯誤的分隔符。如果分隔符是「;」並且您的行包含帶負號的負值(「 - 」)? –