Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Export SQL Query to TXT

Posted on 2012-04-05
5
Medium Priority
?
242 Views
Last Modified: 2012-08-13
Hello, is there a way to allow to download a SQL Query to TXT (csv) without creating the physical TXT file on the hard drive and provide a link? I use VB not C# (asp.net)

Thanks.
0
Comment
Question by:pvg1975
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:pvg1975
ID: 37812691
I will explain better. I have a SQL query that returns about 2,000 records. These records should be exported to a TXT file, but I dont want to create the file on the server's HDD, I was wondering if there's a way to allow the user to download the SQL results on a TXT file without creating such file on the hard drive. Thanks.
0
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 2000 total points
ID: 37815408
Hi pvg1975,

Check this code :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Write("Downloading....")

        Dim sch As New clsReport
        Dim fileData As New clsReport.Letter
        fileData = sch.DownloadLetter(Session("LetterID"))
        Dim ms As System.IO.MemoryStream = fileData.fil

        Dim fil As Byte() = ms.ToArray
        Dim nam As String = fileData.name
        Dim ext As String = fileData.ext
        If Not fil Is Nothing Then
            Try
                ' Response.Clear()
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + nam & "." & ext)
                ' Response.AddHeader("Content-Disposition", nam & "." & ext)
                Response.AddHeader("Content-Length", fil.Length.ToString)
                Response.ContentType = "Application/octet-stream"
                Response.Buffer = True
                Response.BinaryWrite(fil)
            Catch ex As Exception
                Response.Write(ex.Message)
            End Try

        End If


    End Sub

Open in new window


Basically all you need to do is to build fileData string and then use Response.Write not Response.BinaryWrite.

Regards,
Chinmay.
0
 

Author Comment

by:pvg1975
ID: 37819246
Thanks, I found that code too at dotnetspark, but I couldnt make it work, I get an error at

Dim sch As New clsReport
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37819676
Hi pvg1975,

We won't need that. You can remove it. I have given the example code as reference only based on which you can dervie your own code.

Regards,
Chinmay.
0
 

Author Comment

by:pvg1975
ID: 37819935
Yes I figured that out! Thanks :)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question