1
我有一個SSIS包,可以根據一定的標準向用戶發送電子郵件,我現在想跟蹤以這種方式通知並向我們的團隊發送摘要的所有用戶。我是想保存這些變量中通知的列表(串)的usersname,但我似乎無法做到這一點的AA腳本任務,這裏是我的代碼:SSIS包:無法將System.Object轉換爲List(Of String)以存儲在Package變量中?
Public Sub Main()
Dim vars As Variables
If Dts.Variables("Users").Value Is Nothing Then
Dim users As New List(Of String)
users.Add("Enrollees: \n")
Dts.VariableDispenser.LockOneForWrite("Users", vars)
vars.Item("Users").Value = users
End If
'errors out on this line
Dim userList As List(Of String) = DirectCast(Dts.Variables("Users").Value, List(Of String))
'errors out on this line
userList.Add(Dts.Variables("FirstName").Value.ToString() & " " & Dts.Variables("LastName").Value.ToString() & " (" & Dts.Variables("Email").Value.ToString() & ")\n")
Dts.VariableDispenser.LockOneForWrite("Users", vars)
vars.Item("Users").Value = userList
Dts.TaskResult = Dts.Results.Success
End Sub
變量用戶被設置爲Object類型,我知道你可以在那裏存儲複雜的類型,因爲我已經存儲了ADO.NET記錄集,但是我從來沒有通過腳本任務在代碼中完成這些工作。我也嘗試過CType,它給出了同樣的錯誤。我究竟做錯了什麼?
另外我知道我可以只存儲變量作爲逗號分隔在一個字符串中,並稍後分開,但我想知道爲什麼這不工作,並堅持更基於對象的方法。
謝謝。
您收到了什麼具體錯誤? –
無法將System.Object的對象轉換爲System.Collections.Generic.List [String] – SventoryMang