DataReader to pipe delimited file question

Discussion in 'ASP .Net' started by Elmo Watson, Jan 24, 2008.

  1. Elmo Watson

    Elmo Watson Guest

    Right now, I'm querying the database and using a DataReader to retrieve the
    fields, and save to a Pipe delimited text file
    However, it's a little cumbersome, in that I'm using the AppendFormat
    function of the stringBuilder to do it
    Kind of like this:

    While objDR.Read()
    oBuilder.AppendFormat(objDR("MerchantName").ToString.Trim)
    oBuilder.AppendFormat("|" & objDR("VendorID").ToString.Trim)
    oBuilder.AppendFormat("|" & objDR("TransactionDate").ToString.Trim)
    ' .....plus other columns in the database
    end While
    Then, I write the data to the file

    Is there a way I can format this in much fewer lines?

    For instance, in Classic ASP, when retrieving a Recordset, you could iterate
    through the fields, very simply, and format as you would wish.
    Is there something similar in ASP.Net which will allow me to do something
    like this, so that there would be less code?
     
    Elmo Watson, Jan 24, 2008
    #1
    1. Advertisements

  2. Howdy,

    Dim reader As SqlDataReader = Command.ExecuteReader()
    Dim oBuilder As New StringBuilder

    While reader.Read()
    For i As Integer = 0 To reader.FieldCount - 1
    oBuilder.Append(reader(i))
    oBuilder.Append("|")
    Next
    End While

    --
    Milosz


    "Elmo Watson" wrote:

    > Right now, I'm querying the database and using a DataReader to retrieve the
    > fields, and save to a Pipe delimited text file
    > However, it's a little cumbersome, in that I'm using the AppendFormat
    > function of the stringBuilder to do it
    > Kind of like this:
    >
    > While objDR.Read()
    > oBuilder.AppendFormat(objDR("MerchantName").ToString.Trim)
    > oBuilder.AppendFormat("|" & objDR("VendorID").ToString.Trim)
    > oBuilder.AppendFormat("|" & objDR("TransactionDate").ToString.Trim)
    > ' .....plus other columns in the database
    > end While
    > Then, I write the data to the file
    >
    > Is there a way I can format this in much fewer lines?
    >
    > For instance, in Classic ASP, when retrieving a Recordset, you could iterate
    > through the fields, very simply, and format as you would wish.
    > Is there something similar in ASP.Net which will allow me to do something
    > like this, so that there would be less code?
    >
    >
    >
     
    Milosz Skalecki [MCAD], Jan 25, 2008
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lee, wonsun
    Replies:
    1
    Views:
    643
    Jack Klein
    Nov 2, 2004
  2. RyanL
    Replies:
    6
    Views:
    1,009
    Paul McGuire
    Aug 28, 2007
  3. digz
    Replies:
    5
    Views:
    2,742
    Tim Chase
    Mar 19, 2009
  4. Samantha
    Replies:
    7
    Views:
    305
    Samantha
    Mar 7, 2007
  5. J
    Replies:
    8
    Views:
    418
  6. Replies:
    1
    Views:
    570
    ZedGama3
    Apr 14, 2004
  7. Replies:
    1
    Views:
    380
    Ben Morrow
    Jun 2, 2004
  8. Srikant
    Replies:
    1
    Views:
    660
    Greg Bacon
    Sep 29, 2007
Loading...