Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is kinda weird, I have stripped the code to it's bear bones and still it's not doing what it used to do... maybe I cant see the woods for the tree, but I cant see what I have done wrong - : Basically, I am calling out data from a SQL server - pulling it through a loop, in this example just doing it on an mdb file... I created a button that when pressed it exported the data to a *.txt file = doesn't do that anymore, it creates the txt file, but doesn't append the data, any thoughts???

VB
<pre lang="xml"><%@ Page Language=VB Debug=true %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server Language=VB >
    'Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    Dim intBtnClkCount As Integer = 0
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles writeButton.Click

        intBtnClkCount += 1


        ' writeButton.Visible = False
    End Sub
    Sub objWriter(ByVal s As Object, ByVal e As EventArgs)
        Dim FILE_NAME As String = "C:\Users\Fe\Desktop\xml\test.f"
        Dim DBConn As OleDbConnection
        Dim DBCommand As OleDbDataAdapter
        Dim DSPageData As New DataSet
        Dim I As Long
        DBConn = New OleDbConnection( _
            "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
            & "DATA SOURCE=" _
            & Server.MapPath("storage1.mdb;"))
        DBCommand = New OleDbDataAdapter _
            ("Select * from samplesource", DBConn)
        DBCommand.Fill(DSPageData, _
            "samplesource")
        For I = 0 To DSPageData.Tables("samplesource").Rows.Count - 1
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME)

            lblMessage.Text = lblMessage.Text _
                & "<BR>Processed Record: " _
                & DSPageData.Tables("samplesource"). _
                Rows(I).Item("s1")
            objWriter.Close()
        Next


    End Sub


    </SCRIPT>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form id="Form1" runat="server">
<BR><BR>
<asp:label
    id="lblMessage"
    runat="Server"/><asp:Button ID="writeButton" Text="Write" runat="server"
        OnClick="objWriter" />
</form>
</BODY>
</HTML>
Posted
Comments
Orcun Iyigun 13-Aug-11 13:25pm    
You shouldnt add a solution in order to comment. Click 'add comment' button then the member will be notified otherwise he wont.

1 solution

You have create an object of the StreamWriter class.
However, you need to write to it using the Write() or WriteLine() method.

You are simply writing text to a label - lblMessage.Text.
 
Share this answer
 
v2
Comments
thatraja 14-Aug-11 0:24am    
[Comment from OP/Moved from Answer]
do'h !!! Thankyou so much dude!!! nice one

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900