Function ini semoga bisa membuka jalan buat kamu, aku implementasinya di
ASP, sama aja sih, tinggal fieldnya aja kamu ganti, beres deh.
 
Functionnya : 
 
Private Function tulisTXTBaru()
 
        Dim GetCabang As SCRIPT
        Dim a As String
        Dim b As String
        Dim bulan As String = Today.Month
        Dim tahun As String = Today.Year
 
        If DDLBulan.SelectedItem.Text < 10 Then
            Me.Label1.Text = Me.DDLTahun.SelectedItem.ToString + "0" +
Me.DDLBulan.SelectedItem.ToString
        Else
            Me.Label1.Text = Me.DDLTahun.SelectedItem.ToString +
Me.DDLBulan.SelectedItem.ToString
        End If
 
        a = GetCabang.SetAndGetCabangAsal
 
        If a Is Nothing Then
            Me.Response.Write("kosong")
        Else
 
' -- > yang penting yang ini : 
 
            Dim NOMINALINT, Jumlah As String
            Dim int As Integer
            Dim x As String = Today.ToShortTimeString
            Dim fsBaru As New FileStream("C:\Cetak\BARU" & a & ".TXT",
FileMode.Create, FileAccess.Write)
            Dim sBaru As New StreamWriter(fsBaru)
            Dim strspace As String = "
"
            Dim norek, TglPost, Ket, MataUang, Nominal, KodeTrans,
Narasi, KetTambahan, nom As String
 
            Try
 
 
                Dim ia As Integer
                Dim strRow, strResult, strHdr, ias As String
                Dim conDtRe As SqlClient.SqlConnection
                Dim drLap As SqlClient.SqlDataReader
                Dim cmdLap As SqlClient.SqlCommand
                'conDtRe = New SqlClient.SqlConnection("Persist security
info=true;user id=sa;password=sa;data source=192.168.8.111;initial
catalog=Intensif;")
                conDtRe = New SqlClient.SqlConnection("Data
Source=DHNWEB;Initial Catalog=Insentif;Password=sa;User ID=sa")
 
                conDtRe.Open()
                cmdLap = New SqlClient.SqlCommand("Select * from
Tabel_Insentif where Kode_Cabang like '%" & Me.TxtCari.Text & "%' and
StatusCetak = 'N' ", conDtRe)
                drLap = cmdLap.ExecuteReader
                ia = 0
                Do While drLap.Read
 
                    norek = drLap("noRekPendek")
                    TglPost = drLap("tglpost")
                    Ket = drLap("Keterangan")
                    MataUang = drLap("MataUang")
                    Nominal = drLap("Nominal")
                    KodeTrans = drLap("KodeTransaksi")
                    Narasi = drLap("Narasi")
                    KetTambahan = drLap("KeteranganTambahan")
                    nom = Nominal.Replace(".", "")
                    NOMINALINT = nom.Replace(",", ".")
                    'int = CInt(NOMINALINT)
                    'Jumlah = Format(int, "###.00")
 
 
                    strRow = norek &
Microsoft.VisualBasic.Left(strspace, 13 - Len(norek)) & _
                    TglPost & Microsoft.VisualBasic.Left(strspace, 8 -
Len(TglPost)) & _
                    Ket & Microsoft.VisualBasic.Left(strspace, 1 -
Len(Ket)) & _
                    MataUang & Microsoft.VisualBasic.Left(strspace, 3 -
Len(MataUang)) & _
                    Microsoft.VisualBasic.Left(strspace, 17 -
Len(NOMINALINT)) & NOMINALINT & _
                    KodeTrans & Microsoft.VisualBasic.Left(strspace, 4 -
Len(KodeTrans)) & _
                    Narasi & Microsoft.VisualBasic.Left(strspace, 35 -
Len(Narasi)) & KetTambahan & _
                    Microsoft.VisualBasic.Left(strspace, 17 -
Len(KetTambahan)) & vbCrLf
                    strResult = strResult & strRow
                    ia = ia + 1
                Loop
                sBaru.BaseStream.Seek(0, SeekOrigin.End)
                sBaru.WriteLine(strResult & vbCr)
                drLap.Close()
                conDtRe.Close()
                sBaru.Close()
                Me.ValidationSummary1.HeaderText = "Message Information
: "
                Me.CustomValidator1.IsValid = False
                Me.CustomValidator1.ErrorMessage = "Data sudah ditulis
di Text di Program "
 
            Catch ex As Exception
                Me.CustomValidator1.IsValid = False
                Me.CustomValidator1.ErrorMessage = ex.Message
 
                'MsgBox("Error  : " & ex.Source & ":" & ex.Message,
MsgBoxStyle.OKOnly, "Save")
                Exit Function
            End Try
            'MsgBox("Data sudah ditulis di Text di Program ",
MsgBoxStyle.Information, "Create  ")
 
        End If
    End Function
 


[Non-text portions of this message have been removed]

Kirim email ke