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 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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.