DataReader to pipe delimited file question

E

Elmo Watson

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?
 
M

Milosz Skalecki [MCAD]

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top