0

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Kusno
0

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" /> 
    [B]<meta name="DownloadOptions" content="noopen" />   [/B]   
</head>
<body>

In VB code

Imports System.IO

 Sub SaveToTextFile()
        Dim SQL As String = ""
        Dim FileName As String = "JournalEntry-" & Format(Now, "yyMMddHHmmss")
        Dim Path As String = Request.PhysicalApplicationPath & "pdf\" & FileName & ".txt"
        Dim SW As StreamWriter = File.CreateText(Path)

        SQL = "SELECT TransNo, TrxDate, Narrative, CurrencyID, Amount FROM Trx"
        Dim CnJE As New SqlClient.SqlConnection
        If GetCN(CnJE) Then
            Dim CmJE As New SqlClient.SqlCommand(SQL, CnJE)
            Dim RdJE As SqlClient.SqlDataReader
            RdJE = CmJE.ExecuteReader
            With RdJE
                While .Read
                    Dim S As String = ""
                    If SetStringValue(.Item("CurrencyID")) = "IDR" Or SetStringValue(.Item("CurrencyID")) = "JPY" Or SetStringValue(.Item("CurrencyID")) = "ITL" Then
                        S = S & Format(.Item("Amount"), "#############")
                    Else
                        S = S & Format(.Item("Amount"), "#############.#0")
                    End If
                    S = S & ";D;" & Format(.Item("TrxDate"), "ddMMyy") & ";" & SetStringValue(.Item("Narrative"))
                    SW.WriteLine(S)
                    S = ""
                End While
                SetToNothing(CnJE, RdJE, CmJE)
            End With
        End If

        SW.Flush()
        SW.Close() 

        Response.Clear()
        Response.AppendHeader("content-disposition", "attachment; filename=" + FileName + ".txt")
        HttpContext.Current.Response.ContentType = "application/text"
        Response.WriteFile(Path)
        Response.End()
        Response.Close()
    End Sub

Thanks

Edited by Kusno: bold-red

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.