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
Solved

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

Posted on 2011-09-18
3
237 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
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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