Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 write to text file???

Author  Topic 

burwelj
Starting Member

4 Posts

Posted - 2007-09-06 : 09:59:39
Hello,

I'm trying to write the results of a query to a text file. I'm using VB.NET and SQL server 2005. I've been trying to use a StreamWriter and DataReader, but something does not seem to be working. Any and all help is much appreciated. Listed below is my code. Assume all variables are previously defined. The file creates successfully, but no data is being populated into it. Please let me know if any more information is needed. Thanks!

Dim myFile As New FileStream(myPath)
Dim s As New StreamWriter(myFile)
Dim myCommand As New SqlCommand(mySelectQuery, conn)
Dim myReader As SqlDataReader = (myCommand.ExecuteReader())
While myReader.Read
s.WriteLine(myReader.GetSqlValue(1))
End While
myReader.Close()
conn.Close()
   

- Advertisement -