Create a text file

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 10
Reputation: marangajared is an unknown quantity at this point 
Solved Threads: 0
marangajared marangajared is offline Offline
Newbie Poster

Create a text file

 
0
  #1
Sep 22nd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 178
Reputation: Kusno is an unknown quantity at this point 
Solved Threads: 14
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Re: Create a text file

 
0
  #2
Sep 24th, 2009
Originally Posted by marangajared View 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
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
  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
NEVER NEVER NEVER GIVE UP
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC