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!!

8 Comments

  • Can you repost that in C#?

  • 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!

  • 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);
    }

  • 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);

    }

  • public Boolean DTHasChanges(DataTable DT) {
    return (DT != null) ? DT.GetChanges() != null : false;
    }


  • 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

  • [...]that the time to read or visit the content or website pages we have linked to below
    that the[...]…

  • Great weblog here! Also your site lots up fast! What host are you the use of?
    Can I am getting your affiliate hyperlink for the host? I wish my web site loaded up as fast because yours lol

Comments have been disabled for this content.