943,691 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 2276
  • ASP.NET RSS
Sep 22nd, 2009
0

Create a text file

Expand Post »
I want to create or export data from the database (SQL Server 2005) to a text file. the data I need is for THAT DAY ONLY. The text file is required by another system and therefore at the end of the day, I need a report on txt for the transactions done in that day.
Guyz, How do I go about this from ASP.NET interface?
HINT
The data is entered into the database via a payment system that I am developing.
Thank you
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
marangajared is offline Offline
10 posts
since Sep 2009
Sep 24th, 2009
0

Re: Create a text file

I want to create or export data from the database (SQL Server 2005) to a text file. the data I need is for THAT DAY ONLY. The text file is required by another system and therefore at the end of the day, I need a report on txt for the transactions done in that day.
Guyz, How do I go about this from ASP.NET interface?
HINT
The data is entered into the database via a payment system that I am developing.
Thank you
I hope I can help you

In ASPX form
<head runat="server">
    <title>...</title>
    <link rel="stylesheet" href="../../MyStyle.css" type="text/css" /> 
    <meta name="DownloadOptions" content="noopen" />      
</head>
<body>

In VB code
ASP.NET Syntax (Toggle Plain Text)
  1. Imports System.IO
  2.  
  3. Sub SaveToTextFile()
  4. Dim SQL As String = ""
  5. Dim FileName As String = "JournalEntry-" & Format(Now, "yyMMddHHmmss")
  6. Dim Path As String = Request.PhysicalApplicationPath & "pdf\" & FileName & ".txt"
  7. Dim SW As StreamWriter = File.CreateText(Path)
  8.  
  9. SQL = "SELECT TransNo, TrxDate, Narrative, CurrencyID, Amount FROM Trx"
  10. Dim CnJE As New SqlClient.SqlConnection
  11. If GetCN(CnJE) Then
  12. Dim CmJE As New SqlClient.SqlCommand(SQL, CnJE)
  13. Dim RdJE As SqlClient.SqlDataReader
  14. RdJE = CmJE.ExecuteReader
  15. With RdJE
  16. While .Read
  17. Dim S As String = ""
  18. If SetStringValue(.Item("CurrencyID")) = "IDR" Or SetStringValue(.Item("CurrencyID")) = "JPY" Or SetStringValue(.Item("CurrencyID")) = "ITL" Then
  19. S = S & Format(.Item("Amount"), "#############")
  20. Else
  21. S = S & Format(.Item("Amount"), "#############.#0")
  22. End If
  23. S = S & ";D;" & Format(.Item("TrxDate"), "ddMMyy") & ";" & SetStringValue(.Item("Narrative"))
  24. SW.WriteLine(S)
  25. S = ""
  26. End While
  27. SetToNothing(CnJE, RdJE, CmJE)
  28. End With
  29. End If
  30.  
  31. SW.Flush()
  32. SW.Close()
  33.  
  34. Response.Clear()
  35. Response.AppendHeader("content-disposition", "attachment; filename=" + FileName + ".txt")
  36. HttpContext.Current.Response.ContentType = "application/text"
  37. Response.WriteFile(Path)
  38. Response.End()
  39. Response.Close()
  40. End Sub

Thanks
Last edited by Kusno; Sep 24th, 2009 at 4:36 am. Reason: bold-red
Reputation Points: 11
Solved Threads: 17
Junior Poster
Kusno is offline Offline
191 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Horizontal lines in gridview
Next Thread in ASP.NET Forum Timeline: Losing Session Variables in a Frameset





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC