finding changed records

bagel

New member
Joined
Aug 12, 2004
Messages
4
Programming Experience
10+
Hi,

I have a DataGrid on a form that is bound to a disconnected dataset. What I want to be able to do, when the user makes their changes and click on the save button (dataSet.update) would like to get all the rows that will be changed when the update is done, and their original value so that I can store it in a History table.

I know I can use the getChanges methods to get all rows that have been modified, but that doesn't give the original values.

Can anyone help?

Thanks
 
bagel said:
Hi,

I have a DataGrid on a form that is bound to a disconnected dataset. What I want to be able to do, when the user makes their changes and click on the save button (dataSet.update) would like to get all the rows that will be changed when the update is done, and their original value so that I can store it in a History table.

I know I can use the getChanges methods to get all rows that have been modified, but that doesn't give the original values.

Can anyone help?

Thanks

if your using oledb..use the oledbcommandbuilder,if sql...use the sqlcommandbuilder it will do the update,delete,insert in your table..just pass the dataadapter to your commandbuilder.

VB.NET:
Dim ds As New DataSet()
'cn is a connection 
    Dim da As New SqlDataAdapter("select * from employees", cn)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ds.Tables.Add(New DataTable("dt"))
        cn.Open()
        da.Fill(ds.Tables(0))
        DataGrid1.DataSource = ds.Tables(0)
        cn.Close()
    End Sub
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ds.HasChanges Then
            ds.Tables(0).GetChanges()
            Dim ca As New SqlCommandBuilder(da)
            da.Update(ds.Tables(0))
        End If
    End Sub
 
Back
Top