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. Advertising

  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. Advertising

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. RyanL
    Replies:
    6
    Views:
    726
    Paul McGuire
    Aug 28, 2007
  2. digz
    Replies:
    5
    Views:
    2,232
    Tim Chase
    Mar 19, 2009
  3. Samantha
    Replies:
    7
    Views:
    159
    Samantha
    Mar 7, 2007
  4. J
    Replies:
    8
    Views:
    240
  5. Miki Tebeka
    Replies:
    0
    Views:
    177
    Miki Tebeka
    Dec 5, 2012
Loading...

Share This Page