Writing the result of a query to a file

I currently have a dynamic query builder in ASP that the user can display

the results of the query in a table or dump to a double-quote qualified,
coma-delimited file. (to save as a .csv or whatever)
I'm in the process of rebuilding the application in .NET, but have not be
able to figure out how to write to the file in this mannor. Before it seemed
quite simple using set and looping through all the entries writing a line at
a time, but how do you do this in .NET. Below I have my code, which is very
similar to how I populate my datagrid for the same query, but in this
instance would like to write to the file.
Here's what I have and I 'm missing the code that makes this whole thing
work. Any help would be appriciated!!

Dim Query
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim objFSO, objTextFile
objFSO = CreateObject("Scripting.FileSystemObject")
objTextFile = objFSO.CreateTextFile(Server.MapPath("file1.txt")) ' Create
the file
Query = TextBox2.Text ' The query equals the value the user created in
cmd = New SqlCommand(Query)

conn = SQLConnect() ' Call SqlConnect to Create the connection
conn.Open() ' Open The Connection
cmd.Connection = conn ' Set the Connection Property
' Set the DataSource ?
objTextFile.writeline(cmd.ExecuteReader()) ' write to the file ?
' Bind the data to what ?

6/14/2002 12:32:00 PM
asp.net.migrating-from-asp 901 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 0

what is wrong with this script.... i think a no error found it...
9/25/2003 10:57:35 PM

Similar Artilces:

Writing Query Result to txt File
I'm trying to write the results of a query to a text file on the server. I'm able to write the file successfully, but I do not know the syntax to write the contents of a query or recordset to the text file. Could someone show a simple example of how I'd do this? thanks! i usually use: 1; John Doe; New York2; Rick James; Detroit3; Charlie Murphy; Los Angeles  James Hearst.NET Application Developer Have you tried using an old FileSystemObject.  This has all the functions to create files and write away records on your own server. BlueMistOnline, What do you mean? c...

writing file::find results to an file
Hi, I'm using file::find to (obviously!) find files, but I want the results to be placed in a text file so I can send the paths via email to others. Could someone have a look at this code (granted it might and is messy), But look at all lines beginning with * (near the bottom) and tell me why it dumps EVERY file it looks at into my text file. Any help would be appreciated. When i just print out the results to the screen, it works, when I try to put it into a file it doesn't... Thanx a zill... ben #!usr/bin/perl -w use File::Find; use File::Basename; $match=<ST...

Novice DBA looking for Advice on Querying the result of a query of a results of a query of a....
Many thanks in advance! Here's an example of what I'm working on.  Let's say I have a row of data that is returned in a query.  The columns are First, Middle, and last.  We'll say the values in each column, respectively, are 1, 2, and 3. So I run my first query, something akin to SELECT MIDDLE WHERE MIDDLE = 2.  And we get that row.  Excellent. What I'm trying to do, is after that statement is executed, run another one on the webpage that looks like SELECT LAST WHERE LAST = [the value that was returned in the previous statment]. And the k...

Migration question: How do I use a class file with all the files that make a single .Net page?
I'm going to start with how I developed pages in Classic ASP, here goes:default.asp<!-- #include virtual="inc/initialize.asp" --><!-- #include virtual="inc/header.asp -->Insert content here ...<!-- #include virtual="inc/footer.asp --><!-- #include virtual="inc/terminate.asp -->initialize.asp<%' Dim application constants (connection string, etc.)' ...' The constructor of this class would open a connection to the databaseset MyProject = new class_app%>terminate.asp<%' The destructor of this class closes and destroys the database connectionset MyProject = nothin...

.net 1.1 to .NET 2.0 migration generates additional .aspx.xx files
 Hi all,when doing the upgrade in VS 2005 two more additional pages get created, aspx.designer.cs and aspx.resx, do I need to keep these files?Thanks  The designer and resx pages are normal - just ignore them.Don't forget to click "Mark as Answer" on the post that helped you.This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.  Refer below links regarding migration  http://webproject.scottgu.com/CSharp/Migration/Migration.aspx http://rextang.net/blogs/work/archive/2006/04/16/3645.aspx P...

If one query returns any result then the result from other query should be eliminated..
HI, I want to create a query which returns allowed reports for the user. There are two different queries which returns the allowed reports. One returns the reports according to user and other reutrns reports according to the role of user. e.g.Select ReportID from UserReports and  select ReportID from RoleReports (in original scenario both queries are quite complex and large) Requirement is if the first query returns any row then the result of the from the second query should be ignored. IF(Select ReportID from UserReports > 0) Begin Select ReportID from Us...

Combine SQL query result with XML query result
Hi all, Hopefully someone can help me with this: I know how to setup and run a query on an SQL db and I can probably work out how to query an XML file, but how do I take the results of each and combine them into one collection (i'm presuming a dataset)? Once i've created the combined collection, i'd want to order it by some universal identifier present in both datasources e.g. product ID. It's worth pointing out that the XML file would not be in the same format/use the same field names (or number of fields) as the SQL query, so I guess I might need to bind my query resu...

Querying a Queried result...
Hi, is there such a thing as querying a queried result? Example, query 1 produces Result A. Result A's table is stored 'somewhere' to be queried by query 2 which produces Result B If there is, could you kindly direct me to a website with the appropiate article on this topic? Thanks, -Gabian- Yes there is, querying a View is querying a query rewrite. Send me an email the address is in my profile I will send you a Views tutorial I wrote a while back and run a search for query results from View in your BOL(books online) for code samples. Hope this helps. Kind regards, ...

After migration from .Net 1.1 to .Net 3.5 do I have to incorporate new web.config settings in old *.config file
Hi,I have successfully migrated web application from .Net 1.1 to .Net 3.5. Could you let me know whether I have to incorporate setting in new web.config (this new web.config file was generated automatically due to migration) into old *.config file?FYI: Old *.config file contains all application level settings required. So I will continue to use old.config file by removing new web.config file. Settings which are in new web.config file are:<configSections><sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup,...

Writing file to browser needs write permissions to show file
 Hi all, I have a page called GetFile.aspx which does the simple job of converting the aspx document into either a word or PDF file for downloading of viewing online (dependant on user browser settings) but im having an issue where the file im including must have write access for it to be opened and shown in the browser.   Dim fs As New FileStream(FileName, FileMode.Open) Using (fs) Dim data() As Byte = New Byte(fs.Length) {} Dim br As BinaryReader = New BinaryReader(fs) br.Read(data, 0, data....

Writing formatted results to a file
------_=_NextPart_001_01C1E569.B001A870 Content-Type: text/plain; charset="iso-8859-1" Hi guys I was wondering if you could help me. Does anybody know how to write formatted results to a file ? I am getting the following error : write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, <SUMMARYTMP> line 5. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, <SUMMARYTMP> line 15. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, <SUMMARYTMP> line 21. This is the section of my perl code r...

Write Qry results to file
I'd like to create an event to dump a query result to a file on a daily basis. From ISQL, this works great: SELECT ... FROM mytable; OUTPUT TO myfile FORMAT ASCII; But, the OUTPUT statement only works in ISQL. Is there something comperable that works elsewhere? My only other option that I can find is to use ISQL in a batch mode and invoke it from a OS command. Yuck. Thanks! Using SQLA 9.0.2.something x64 edition on WinServer 2003 x64 See UNLOAD SELECT. Caution: the file spec is relative to the computer running the database engine, whereas with ISQ...

Write query results to pdf
I am returning some rows and would like to write it to a pdf. I have done the same with excel.But how to go about writing contents to pdf. I am using C#, .NET 2003 hi, i have an excel class also that i use to export to excel. As this is build into .NET code is just there to be used. i would imagine you'd need to buy or find open source class that will do this. on the other note, office 2007 does have a Save as PDF feature, maybe there is something there to look into.  http://www.developerfusion.co.uk/show/4266/ http://www.asp.net/community/control-ga...

writing to a file (vb.net)
 im trying to write to a file. the code works fine on my local machine but when i put it on the server it dosnt.Im using the file.writealltext(server.mappath(../1/folder/folder/), text)but when i upload and trigger the event tat performs this it gives me an DirectoryNotFoundException error. the reason it does this is because its trying to write to C://websites/admn/etc...... any ideas why or how to fix this. need answer asapthanks   carroll.iain: im trying to write to a file. the code works fine on my local machine but when i put it on the server it dosnt. Im using ...

Web resources about - Writing the result of a query to a file - asp.net.migrating-from-asp

File:P writing.svg - Wikipedia, the free encyclopedia
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License , Version 1.2 or ...

Student writing: grade 4 students explore animal rights
St Kilda Primary School students have been learning the power of persuasive writing. Here three students explore shark culling and horse racing. ...

Review: Apple Pencil is the best iPad writing tool yet … if you can handle the Pro’s size
... While Pencil is not required to use the iPad Pro, it’s especially interesting because it’s Apple’s first official solution for handwriting, ...

Friday Morning Open Thread: Can We Get That In Writing, Lady?
... STOP HELPING ALREADY, ‘KAY? , what’s on the agenda as we wrap up the week? The post Friday Morning Open Thread: Can We Get That In Writing, ...

Don't Lose Confidence in Your Writing
... originally published on November 20th. Mel You're as good as anyone else! That's usually the opening to blog posts about how to keep on writing, ...

"Writing about Taylor Swift is a horrific ordeal for me because her twinkly persona is such a scary flashback ...
Writes Camille Paglia. Swift herself should retire that obnoxious Nazi Barbie routine of wheeling out friends and celebrities as performance ...

On Gratitude and Writing Your Own Story
... after all this, it’s time that I realize that my story only needs me to complete it. I don’t need to wait for my story to be written. I’m writing ...

Jaden Smith ‘sees himself as a modern-day prophet’ & he’s writing a book
I feel sorry for the Smith kids, Jaden and Willow. They have all that money, access and potential, and they’re just… struggling, I think. Part ...

App turns your writing into trippy 3D images
It's easy to imagine a piece of art in your head, but making it real is another matter if you're not an artist. Wouldn't it be nice if you could ...

EXCLUSIVE: Anna and Josh Duggar Are Writing Love Letters to Each Other, Source Says
EXCLUSIVE: Anna and Josh Duggar Are Writing Love Letters to Each Other, Source Says

Resources last updated: 12/11/2015 4:00:20 PM