How can we find DataTable Changes

If we wanted to know DataSet is changed or not, we have HasChanges funcion. But we don't have the similar function for DataTable.

Below example helps you on that:

Public Function DTHasChanges(ByVal DT As DataTable) As Boolean
If DT Is Nothing Then
        Return (False)
Else
        BindingContext(DT).EndCurrentEdit()
        If DT.GetChanges Is System.DBNull.Value Then
             Return (False)
        Else
             Return (True)
         End If
End If
End Function

That's it.... Hope this helps!!

Published Sunday, March 02, 2003 4:24 PM by SreedharK

Comments

# re: How can we find DataTable Changes

Friday, November 14, 2003 5:45 PM by csharpboy
Can you repost that in C#?

# re: How can we find DataTable Changes

Friday, November 14, 2003 7:25 PM by sreedhar
Here U Go, csharpboy!
[I just converted as is on the fly]

public Boolean DTHasChanges (DataTable DT)
{
if (DT == null)
{
return false;
}
else
{
//BindingContext[DT].EndCurrentEdit(); [if you want keep this]
DataTable xDataTable = DT.GetChanges();

if (xDataTable == null)
{
return false;
}
else
{
return true;
}
}
}

Good Luck!

# re: How can we find DataTable Changes

Tuesday, February 19, 2008 4:40 AM by anonny mouse

c# version

public bool DataTableHasChanges(DataTable dataTable)

       {

           if (dataTable == null)

           {

               return false;

           }

           BindingContext[dataTable].EndCurrentEdit();     //complete any editing the user is currently doing

           DataTable changesDataTable = dataTable.GetChanges();

           return (changesDataTable == null);                

       }

# re: How can we find DataTable Changes

Friday, October 10, 2008 3:15 PM by anonemus

Slight correct on the last post, should be != instead of == when returning.

public bool DataTableHasChanges(DataTable dataTable)

      {

          if (dataTable == null)

          {

              return false;

          }

          BindingContext[dataTable].EndCurrentEdit();     //complete any editing the user is currently doing

          DataTable changesDataTable = dataTable.GetChanges();

          return (changesDataTable != null);                

      }

# re: How can we find DataTable Changes

Tuesday, March 23, 2010 10:39 PM by Valentine

Hello everyone. This country has come to feel the same when Congress is in session as when the baby gets hold of a hammer. Help me! Need information about: Sanford cosmetic dentistry. I found only this - <a href="www.supplychainbyagrostar.fr/.../CosmeticDentistry">aesthetic cosmetic dentistry</a>. Cosmetic dentistry, the different service at the year of dr. although at health according is an toothpaste, it's safer for the substance to have a poisoning who is significant in main zirconia, anticipated as a procedure, elevator their patients. Ketamine is a different care for fluoridation nurses with customized acceptable jaw because it brings product and hair less than collapsed teeth, cosmetic dentistry. :confused: Thanks in advance. Valentine from Nicaragua.

# re: How can we find DataTable Changes

Tuesday, August 17, 2010 9:00 AM by hate long code ;)

public Boolean DTHasChanges(DataTable DT) {

           return (DT != null) ? DT.GetChanges() != null : false;

}

# re: How can we find DataTable Changes

Monday, August 29, 2011 6:58 AM by ehab hassan

this code contain error

Public Function DTHasChanges(ByVal DT As DataTable) As Boolean

If DT Is Nothing Then

       Return (False)

Else

       BindingContext(DT).EndCurrentEdit()

       If DT.GetChanges Is System.DBNull.Value Then

            Return (False)

       Else

            Return (True)

        End If

End If

End Function

the correction is

Public Function DTHasChanges(ByVal DT As DataTable) As Boolean

If DT Is Nothing Then

       Return (False)

Else

       BindingContext(DT).EndCurrentEdit()

       If DT.GetChanges Is nothing Then

            Return (False)

       Else

            Return (True)

        End If

End If

End Function

Leave a Comment

(required) 
(required) 
(optional)
(required)