Solved

Need help with saving saving syscreator and sysmodifier on records how as been change added?

Posted on 2011-09-18
3
234 Views
Last Modified: 2012-05-12
I want to add some logging code to records that has been change or added.

I've add the followings fields to my tables

Syscreator - int
Syscreated - datetime
Sysmodifier - int
Sysmodifed -datetime

How can i automatic update all records with this info if there is something added or changed.

I user vb.net and a SQL server.

On form close I check if the is something changed or added or deleted.

Hope to here from somebody!

Bart
0
Comment
Question by:prinsbj
3 Comments
 
LVL 15

Accepted Solution

by:
x77 earned 500 total points
Comment Utility
If you have a DataTable, you can do:

  For Each Row As DataRow In MyTable.Rows
      If Row.RowState = DataRowState.Added Then
         'Log - Added Row
         'Set Syscreator ,Syscreated ,Sysmodifier ,Sysmodifed
      ElseIf Row.RowState = DataRowState.Modified Then
         'Log - Modified Row
         'Set Sysmodifier ,Sysmodifed
      End If
  Next

Do it Before DataAdapter.Update
Note. You can do it with  DataBase.Triggers, but I am not expert on SqlServer.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Are you using DataAdapters to update the DB? If so, use the RowUpdating event

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.rowupdating.aspx

0
 

Author Closing Comment

by:prinsbj
Comment Utility
It works great!

Thank you.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

10 Experts available now in Live!

Get 1:1 Help Now