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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 script task streamwriter remove last comma
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

United Kingdom
36 Posts

Posted - 11/19/2013 :  06:09:14  Show Profile  Reply with Quote

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 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())



  ' 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())


  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000