how to read fields from a sql table and write to a text file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need a example code of how to read 9 fields (field1, field2,field3.....)
from a sql table, store data in varibles and then write these varibles to a
text file, using vb.net.

I have see many ways than show how to export from a text file to a table but
not from a table to a text file.

I will apreciate any help.
 
=?Utf-8?B?R2Vsbw==?= said:
I need a example code of how to read 9 fields (field1,
field2,field3.....) from a sql table, store data in varibles and then
write these varibles to a text file, using vb.net.

I have see many ways than show how to export from a text file to a table
but not from a table to a text file.

There is no direct way to output to a text file, unless you want XML. But
just open a stream to a text file and write them out yourself.
 
This is easier than you think.
http://www.databasejournal.com/features/mssql/article.php/3391761 discusses
how to use BCP to export the contents of a table to a flat (delimited) file.
It's fast, light and very easy. BCP can also be called from an application
by setting up a BCP TSQL command and using ExecuteNonQuery against it. In
ADO.NET 2.0 it can be called using the SqlBulkCopy class.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top