SQL Server Forums
Profile | Register | 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
 New Topic  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 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())



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