Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 script task streamwriter remove last comma

Author  Topic 

MrBloom
Starting Member

36 Posts

Posted - 2013-11-19 : 06:09:14

Hi I'm using streamwriter to write from a table to a csv file in a script task. I use a comma, stored as a variable as the delimiter. The problem is that a comma is written as the last character of each line and I would like to remove this. How could I do this?
My vb.net code is below

Many thanks



Dim sw As StreamWriter = Nothing


sw = New StreamWriter(filePath, False)



' write column headers


For i = 0 To dt.Columns.Count - 1

sw.Write(dt.Columns(i).ToString() & Dts.Variables("User::VarDelimeter").Value.ToString())


Next

sw.WriteLine()

' write data

For Each row As DataRow In dt.Rows
Dim array As Object() = row.ItemArray


For i = 0 To array.Length - 2

sw.Write(array(i).ToString() & Dts.Variables("User::VarDelimeter").Value.ToString())
Next


sw.WriteLine()
Next


   

- Advertisement -