Please start any new threads on our new site at http://forums.sqlteam.com. 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!
Username:
Password:
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  

MrBloom
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 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


  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.07 seconds. Powered By: Snitz Forums 2000