|
-
Jul 29th, 2008, 02:55 PM
#1
Thread Starter
Hyperactive Member
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:
' Save Records
Private Sub SaveRecords()
If ds.HasChanges() Then
Dim da As SqlDataAdapter = Nothing
Dim cb As SqlCommandBuilder = Nothing
da = New SqlDataAdapter("Select " & _
"PosiPayID, " & _
"TranType, " & _
"TranDate, " & _
"TranAmt, " & _
"TranDesc, " & _
"RefNbr, " & _
"Processed " & _
"FROM PosiPay.dbo.PosiPayTransactions " & _
"Order by RefNbr", Con)
da.TableMappings.Add("Table", "PosiPay")
Try
Try
ExportDS(ds)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
cb = New SqlCommandBuilder(da)
da.Update(ds)
MessageBox.Show("Changes Saved", _
"Success", _
MessageBoxButtons.OK)
Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & _
ex.Source & vbNewLine & _
ex.StackTrace, "Save Change Error", _
MessageBoxButtons.OK)
Finally
cb.Dispose()
da.Dispose()
End Try
Else
Exit Sub
End If
End Sub
-
Jul 29th, 2008, 04:46 PM
#2
Lively Member
Re: Export Only the Changed Data in a dataset
FastEddie,
Use the dataset's GetChanges method.
Kerry Moorman
-
Jul 29th, 2008, 05:09 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|