Open()
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = con
cmd.CommandText = "Select LastName from Employees"
Dim rst As SqlClient.SqlDataReader
rst = cmd.ExecuteReader
Dim i As Integer
i = rst.FieldCount
MsgBox(i)
Dim sb As New StringBuilder("", 200)
Dim k As Integer
While rst.Read
sb.Append(rst.Item(k))
sb.Append(vbCrLf)
'MsgBox(rst1.Item(j))
End While
MsgBox(sb.ToString)
My.Computer.FileSystem.WriteAllText(
"C:\ScriptWrite.txt", sb.ToString, False)
Dts.TaskResult = Dts.Results.Success
End Sub
Chapter 19
[ 285 ]
As you can see, the StringBuilder is brought in to build a string consisting of
employee's name, and the final message box displays this string.
In the next statement, you see how the string is written to a text file
created on-the-fly. Of course, you get the intellisense help, as shown in the
next screenshot.
4. Change the PrecompileScriptIntoBinaryCode line item to false, in the Script
list item of the Script Task Editor.
5. Click on the OK button on the Script Task Editor.
6. Build the project and execute the Script Task "Copy Employees names
to a file".
The program starts up and the Script Task turns green and you will see a file
created in the C:\ drive, as shown below. The first message box shows the
number of fields which is 1 in this example. The second message box shows
the names of all the employees in a message box. The C:\ScriptWrite.txt
file is shown in the next figure.
Package with a Script Task
[ 286 ]
Summary
This chapter described several examples of using the Script Task.
Pages:
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200