Results 1 to 3 of 3

Thread: Urgent help - saving data as a text file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2003
    Location
    Exeter - UK
    Posts
    22

    Urgent help - saving data as a text file

    Please can anyone help?

    I have a small access database that the user can update via my vb application (add/delete/print etc.)

    I want to add a button that when clicked will save all the data as well as a few fixed characters that need to be added ie. "F13" at the beginning of each row into a text file called extel.dat.

    The reason for this is the datadase holds details of price changes for our accounting system which we can import.

    If the fields are - Sedol= 0012342, Bid=23.45, Offer=30.11 I need the line in the text file to be:-

    F13001234200023450003011

    Is this possible?

    I've attached some current code below

    Many thanks

    Mark.

    Public Sub LoadDataSet()
    'Create a new dataset to hold the records returned from the call to FillDataSet.
    'A temporary dataset is used because filling the existing dataset would
    'require the databindings to be rebound.
    Dim objDataSetTemp As Impart_Price_DBMH.JoveDB
    objDataSetTemp = New Impart_Price_DBMH.JoveDB()
    Try
    'Attempt to fill the temporary dataset.
    Me.FillDataSet(objDataSetTemp)
    Catch eFillDataSet As System.Exception
    'Add your error handling code here.
    Throw eFillDataSet
    End Try
    Try
    'Empty the old records from the dataset.
    objJoveDB.Clear()
    'Merge the records into the main dataset.
    objJoveDB.Merge(objDataSetTemp)
    Catch eLoadMerge As System.Exception
    'Add your error handling code here.
    Throw eLoadMerge
    End Try

    End Sub

    Public Sub UpdateDataSource(ByVal ChangedRows As Impart_Price_DBMH.JoveDB)
    Try
    'The data source only needs to be updated if there are changes pending.
    If (Not (ChangedRows) Is Nothing) Then
    'Open the connection.
    Me.OleDbConnection1.Open()
    'Attempt to update the data source.
    OleDbDataAdapter1.Update(ChangedRows)
    End If
    Catch updateException As System.Exception
    'Add your error handling code here.
    Throw updateException
    Finally
    'Close the connection whether or not the exception was thrown.
    Me.OleDbConnection1.Close()
    End Try

    End Sub
    Public Sub FillDataSet(ByVal dataSet As Impart_Price_DBMH.JoveDB)
    'Turn off constraint checking before the dataset is filled.
    'This allows the adapters to fill the dataset without concern
    'for dependencies between the tables.
    dataSet.EnforceConstraints = False
    Try
    'Open the connection.
    Me.OleDbConnection1.Open()
    'Attempt to fill the dataset through the OleDbDataAdapter1.
    Me.OleDbDataAdapter1.Fill(dataSet)
    Catch fillException As System.Exception
    'Add your error handling code here.
    Throw fillException
    Finally
    'Turn constraint checking back on.
    dataSet.EnforceConstraints = True
    'Close the connection whether or not the exception was thrown.
    Me.OleDbConnection1.Close()
    End Try

    End Sub

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    It is certainly possible. By the looks of your code, it seems like you are using VB.Net, which I am not yet up to speed on. If this was VB6, I would use the "legacy" BASIC statements to do text file processing (Open, Print, etc.). I believe these are gone in .NET, and I am assuming you need to use the FSO or whatever the .NET libraries provide for text file processing. In any event, the basic logic behind your button would be:
    1. SELECT the required fields from your table, returning a recordset.
    2. Open the text file for output
    3. Loop thru this recordset, and for each row, use the string handling functions and format functions (is Format still around in .NET?) to generate a string consisting of the data required for your text file record, then write the text file record.
    4. Close the text file.
    "It's cold gin time again ..."

    Check out my website here.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2003
    Location
    Exeter - UK
    Posts
    22
    Hi Bruce, thanks for the guidance - I've only been using .net for a few weeks so I've got quite a lot to learn.

    Thanks again.

    Mark.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width