Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi...can anyone tell me what is wrong with this function to write data to a file from a datareader??

 

Function WriteCSV(ByRef reader As SqlDataReader)
       Dim strFile As String
       strFile = "D:\CSVData.csv"
       Dim writer As New StreamWriter(strFile, True)
       While reader.Read
           writer.WriteLine(reader(0))
           writer.WriteLine(reader(0))
       End While
       'fs.Close()
   End Function

I am calling this function from here:

 

Dim command As SqlCommand = New SqlCommand("Select * FROM Products", DBConnection)
Dim reader As SqlDataReader = command.ExecuteReader(CommandBehavior.CloseConnection)
WriteCSV(reader)
dgrOut.DataSource = reader
dgrOut.DataBind()

For some reason, the datagrid operations after the WriteCSV()function is called are not executing...

 

Thanks,

SJ

[edit]Please use

 tags [/ vb][/color] [/edit]
Edited by Robby

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...