Click here to Skip to main content
13,899,744 members
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 28 Jun 2010
Licenced CPOL

Implementing WinForms Audit Trail using Binding Source

, 28 Jun 2010
Rate this:
Please Sign up or sign in to vote.
Using BindSource control to implement Windows Forms applications Audit trial in .NET


Implementing Audit Trail using Binding Source is one of the methods of auditing user interactions with Windows Forms in .NET application.

Such a method can help development with any methodology using third parties.

See Implementing Audit Trail using Entity Framework.


A developer who is involved in Windows Forms applications may get stuck deciding which method to use or how to audit the application. The simplest way is to audit the database using triggers. But in fact, this method has many sensitive views, one of them is that if you save the original changed record into audit table; you have to get the actual values of related table. i.e., if the Employee table has a field of cityID, that cityid has value of 15 which is Cairo, if another user updates the city table and sets city of Cairo into Alex, then the first user audit will show the changes from Paris into Alex not into Cairo.

The proposed method is to develop a way to save the current readable values to user at the time of changing.

Using BindingSource control which is most used by any developer, you can audit the current working table prior to actual values represented to user's screen.

Using BindingComplete event of binding source, you track user interaction with the screen, finally when saving changes, you can also save the instance of the audit object.

Using the Code

To use this method, you may:

  • Create a new Windows form
  • Add and define your BindingSource object in form
  • Add BindingComplete event to above bindingSource object to track user changes as follows:
// reading from database
if (e.BindingCompleteContext == BindingCompleteContext.ControlUpdate && 
if (! auditDictionary.ContainsKey(e.Binding.BindingMemberInfo.BindingField))
string OldValue = ReadDisplayValue(e.Binding.Control);
AuditTrial audit = new AuditTrial(e.Binding.BindingMemberInfo.BindingField, OldValue);

if (e.BindingCompleteContext == BindingCompleteContext.DataSourceUpdate && 
if (auditDictionary.ContainsKey(e.Binding.BindingMemberInfo.BindingField))
auditDictionary[e.Binding.BindingMemberInfo.BindingField].NewValue = 

The above method writes values into auditDictionary automatically adding a field with its values.

Finally, you may save the object of auditDictionary into database as Audit entry.

Points of Interest

If you are using such methods, I recommend setting this code into your base forms for your applications, as it is in generic form and can be applied into any data Provider.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

No Biography provided

You may also be interested in...


Comments and Discussions

GeneralNo an article... Pin
Dave Kreskowiak29-Jun-10 2:55
mveDave Kreskowiak29-Jun-10 2:55 
GeneralComments Pin
Md. Marufuzzaman29-Jun-10 1:52
mentorMd. Marufuzzaman29-Jun-10 1:52 
GeneralNot an article Pin
R. Giskard Reventlov28-Jun-10 22:15
professionalR. Giskard Reventlov28-Jun-10 22:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190306.1 | Last Updated 29 Jun 2010
Article Copyright 2010 by Abdelmawgoud M. Meabed
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid