Results 1 to 3 of 3

Thread: Export Only the Changed Data in a dataset

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Export Only the Changed Data in a dataset

    I want to export only the changed data in my dataset. There is another sub that loads the dataset when the form loads. This (sub below) is ran when the user closes the form. It updates the table with any changed values. I would like to catch all the records that have changed in the dataset and export them to a csv file. I already have the export part figured out but the way it is now it is exporting the entire dataset and not just the changed rows.
    VB Code:
    1. ' Save Records
    2.     Private Sub SaveRecords()
    3.         If ds.HasChanges() Then
    4.             Dim da As SqlDataAdapter = Nothing
    5.             Dim cb As SqlCommandBuilder = Nothing
    6.             da = New SqlDataAdapter("Select " & _
    7.                 "PosiPayID, " & _
    8.                 "TranType, " & _
    9.                 "TranDate, " & _
    10.                 "TranAmt, " & _
    11.                 "TranDesc, " & _
    12.                 "RefNbr, " & _
    13.                 "Processed " & _
    14.                 "FROM PosiPay.dbo.PosiPayTransactions " & _
    15.                 "Order by RefNbr", Con)
    16.             da.TableMappings.Add("Table", "PosiPay")
    17.             Try
    18.                 Try
    19.                     ExportDS(ds)
    20.                 Catch ex As Exception
    21.                     MessageBox.Show(ex.Message)
    22.                 End Try
    23.                 cb = New SqlCommandBuilder(da)
    24.                 da.Update(ds)
    25.                 MessageBox.Show("Changes Saved", _
    26.                                 "Success", _
    27.                                 MessageBoxButtons.OK)
    28.             Catch ex As Exception
    29.                 MessageBox.Show(ex.Message & vbNewLine & _
    30.                                 ex.Source & vbNewLine & _
    31.                                 ex.StackTrace, "Save Change Error", _
    32.                                 MessageBoxButtons.OK)
    33.             Finally
    34.                 cb.Dispose()
    35.                 da.Dispose()
    36.             End Try
    37.         Else
    38.             Exit Sub
    39.         End If
    40.     End Sub

  2. #2
    Lively Member
    Join Date
    Jul 2008
    Posts
    107

    Re: Export Only the Changed Data in a dataset

    FastEddie,

    Use the dataset's GetChanges method.

    Kerry Moorman

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Export Only the Changed Data in a dataset

    Before you update the data to your database, use dataset.getchanges as suggested by Kmoorman to get the changes and loop thru the tables/rows of the changed dataset/datatable to write your csv file(s).
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

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