Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Programatically creating a csv file


Message #1 by "Greg Partin" <GPartin@c...> on Mon, 24 Mar 2003 09:33:53 -0700
Hi All,

I need to programatically create a csv file from some values in a
database.  Right now my code is this:

   objText = New
System.IO.StreamWriter(CStr(Current.Application("g_download_dir_share_name"))
& "\EXPORT\" & intRandomNumber & "\" & Me.strUniqueKey & ".csv")

  For Each dtTable In dsdataset.Tables
                    For Each dtRow In dtTable.Rows
                        For Each dtdatacolumn In dtTable.Columns
                            If IsDBNull(dtRow(dtdatacolumn.ColumnName))
Then
                                objText.Write("""NULL""" & vbTab)
                            Else
                                objText.Write("""" &
dtRow(dtdatacolumn.ColumnName) & """" & vbTab)
                            End If
                        Next
                        objText.Write(vbCrLf)
                    Next
                Next

But when opening the file via Excel it doesn't import very well.  If I
rename to .txt and import it then it looks great.  Anyone have any
examples or leads on this topic?

Thanks
Greg

Greg Partin
Software Engineer

CompassLearning, Inc.
2400 N. Commerce Pkwy.
Suite #404
Weston, FL  33326
Message #2 by "Will Swim" <wswim@p...> on Mon, 24 Mar 2003 09:26:26 -0800
Greg,
I'm not sure if this is what you want but here goes. A csv file is
comma separated values. try replacing the vbtab with a comma and see
if it works right.

> Hi All,
>
> I need to programatically create a csv file from some values in a
> database.  Right now my code is this:
>
>    objText = New
> System.IO.StreamWriter(CStr(Current.Application("g_downloa
> d_dir_share_name"))
> & "\EXPORT\" & intRandomNumber & "\" & Me.strUniqueKey & ".csv")
>
>   For Each dtTable In dsdataset.Tables
>                     For Each dtRow In dtTable.Rows
>                         For Each dtdatacolumn In dtTable.Columns
>                             If
> IsDBNull(dtRow(dtdatacolumn.ColumnName))
> Then
>                                 objText.Write("""NULL""" & vbTab)
>                             Else
>                                 objText.Write("""" &
> dtRow(dtdatacolumn.ColumnName) & """" & vbTab)
>                             End If
>                         Next
>                         objText.Write(vbCrLf)
>                     Next
>                 Next
>
> But when opening the file via Excel it doesn't import
> very well.  If I
> rename to .txt and import it then it looks great.  Anyone have any
> examples or leads on this topic?
>
> Thanks
> Greg
>
> Greg Partin
> Software Engineer
>
> CompassLearning, Inc.
> 2400 N. Commerce Pkwy.
> Suite #404
> Weston, FL  33326
>


  Return to Index