SSIS 脚本任务读取文件

读取文件内容到变量
本文介绍了一段VB.NET代码,该代码用于从指定文件中读取所有内容并将其存储在一个名为content的变量中。通过使用StreamReader类,该程序能够逐行读取文件,并将每一行追加到StringBuilder对象中。

 

变量fileName输入参数,读取文件内容放到变量content中。

 1 Public Sub Main()
 2         '
 3         ' Add your code here
 4         '
 5         Dim filename As String
 6         Dim content As StringBuilder
 7         content = New StringBuilder
 8         filename = Dts.Variables("fileName").Value.ToString()
 9 
10         Try
11             ' Create an instance of StreamReader to read from a file.
12             Using sr As StreamReader = New StreamReader(filename)
13                 Dim line As String
14              
15                 Do
16                     line = sr.ReadLine()
17                     content.AppendLine(line)
18                 Loop Until line Is Nothing
19                 sr.Close()
20 
21             End Using
22 
23             Dts.Variables("content").Value = content.ToString()
24 
25         Catch E As Exception
26           
27             Console.WriteLine(E.Message)
28         End Try
29 
30 
31 
32         Dts.TaskResult = Dts.Results.Success
33     End Sub
34 
35 

转载于:https://www.cnblogs.com/yg_zhang/archive/2008/10/18/1313911.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值