writing a datareader to a file

Results 1 to 2 of 2

Thread: writing a datareader to a file

  1. #1
    Join Date
    Dec 1969

    Default writing a datareader to a file

    I&#039;d like to write the data returned by a stored procedure to a file. I have the following codes that creates a file successfully, but the file when opened has this in it: System.Data.SqlClient.SqlDataReader.<BR><BR>Privat e Sub CreateFile()<BR> Dim oSteamWriter As StreamWriter<BR><BR> &#039;get recordset<BR> GetData()<BR><BR> &#039;create file and write to it<BR> oSteamWriter = File.CreateText(Server.MapPath("downloadmyfile.csv "))<BR> oSteamWriter.WriteLine(oDr)<BR> oSteamWriter.Close()<BR> End Sub<BR><BR>GetData() grabs the recordset as a datareader. I figured that maybe the datareader must be converted to a string value first before passing it as a parameter to the WriteLine method, althouth this method can accept an object? I used to do be able to do this in Classic asp, but I used GetString() to fetch the records from the database.<BR><BR>Thanks for any suggetsions.

  2. #2
    Join Date
    Dec 1969

    Default RE: writing a datareader to a file

    You have to iterate the reader and write the value of each column.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts