Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataReader to pipe delimited file question

Reply
Thread Tools

DataReader to pipe delimited file question

 
 
Elmo Watson
Guest
Posts: n/a
 
      01-24-2008
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").ToStri ng.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?


 
Reply With Quote
 
 
 
 
Milosz Skalecki [MCAD]
Guest
Posts: n/a
 
      01-25-2008
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").ToStri ng.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?
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Help "joining" two files delimited with pipe character ("|") Miki Tebeka Python 0 12-05-2012 06:17 PM
converting pipe delimited file to fixed width digz Python 5 03-19-2009 05:40 PM
convert non-delimited to delimited RyanL Python 6 08-28-2007 12:06 AM
Can someone point me in the right direction? Pipe Delimited Files& Hashes... Samantha Ruby 7 03-07-2007 04:32 PM
formating pipe delimited file J Perl Misc 8 02-16-2004 04:03 AM



Advertisments