find out if a field has changed in a datatable

Posted on 2004-11-15
Last Modified: 2010-04-24
How can I find out if a field has changed in a data table?

I am trying to create an audit record of any changes that are made to the data in a table which is bound to textbox controls on a form. Before I insert a new audit record, I need to figure out which values are different from the underlying data.

Question by:brokeMyLegBiking
    LVL 5

    Expert Comment

    Well, I would define 2 data sets. Load the two at the begining of the audit, then at the time to prefomr  the audit, I would take the dataset that was tied to your datagrd or what ever. And I would comapre them line by line like this.

    dim i, j as integer
    while i < then dataset1.tables(0).rows.count 'no compiler in front of me  so count may not be  exactly where i typed it
    While j < dataset1.tables(0).colums.count ' no compiler so you may have to explorer to find this count
    if dataset1.tables(0).rows(i).item(j) = dataset2.tables(0).rows(i).items(j) then
    'no diffrences so do notin
    'diffrence here so do audit
    end while
    end while

    LVL 1

    Accepted Solution

    create a view of the table

    Dim dv As New DataView(Me.OfficeInfoDS.dtOfficeAddress)

    dv.RowStateFilter = DataViewRowState.ModifiedCurrent
    For Each dvItem As DataRowView In dv
    if textbox1.text <> dvItem.Item("Contacts_ID"))
      ' data has changed

    end if

    LVL 4

    Author Comment

    MsFox, that sounds right, let me try that.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now