Solved

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

Posted on 2011-09-18
3
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
x77 earned 500 total points
ID: 36556697
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
ID: 36570432
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
ID: 36593537
It works great!

Thank you.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 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