PC Review


Reply
Thread Tools Rate Thread

DataReader to pipe delimited file question

 
 
Elmo Watson
Guest
Posts: n/a
 
      24th Jan 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").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?


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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Pipe-Delimited CSv File stevieb Microsoft Excel Misc 3 7th Aug 2008 08:08 PM
Retrieving Pipe (|) delimited text file into ADO Recordset mark Microsoft Excel Programming 2 5th Feb 2008 02:15 AM
Identify last row of record in a pipe-delimited text file =?Utf-8?B?RWRtdW5k?= Microsoft Excel Programming 4 24th Oct 2007 03:41 PM
Save file as text pipe delimited Ashley Microsoft Excel Programming 0 5th May 2004 06:38 PM
Export file to pipe-delimited format Doris Microsoft Access External Data 1 26th Aug 2003 01:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:52 AM.