Populate "CreatedBy" and "LUpdatedBy" fields at INSERT and UPDATE

Posted on 2006-05-22
Medium Priority
Last Modified: 2010-04-23

I wanted to find out the best strategy (and the source code to implement it) to use at INSERT and UPDATE time.  I have a WinForms application developed in VS2005 and SQLServer 2000.  The current user ID is stored in a global variable g_userid and I am using a DataGrid1 bound to a daComms.

Is it better to populate CreatedBy and LUpdatedBy fields using custom InsertCommand and UpdateCommand of the daComms or should Triggers be used to do that.  Sample codes for both methods are needed and would help me a lot.

Question by:escap-fss
  • 2
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16732863
It depends if the trigger has access to the values of "CreatedBy" that should be used.
if the trigger can do, it should do it, as this removes the coding from the application.

otherwise, using the InsertCommand and UpdateCommand works also fine.

Author Comment

ID: 16732920
Thanks for the thoughts.

As I mentioned, the values are stored in a global variable in the application.  Can you give some code samples for the Trigger AND the InsertCommand and UpdateCommand methods.

The table's structure is as follows:

CommID (identity)
CommRem (text)
CommRecvd (date)
CreatedBy (text)
LUpdatedBy (text)

The CreatedBy and LUpdatedBy fields are in the same table where the record is being inserted.

LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 100 total points
ID: 16732947
>As I mentioned, the values are stored in a global variable in the application.
then, you cannot use the trigger solution.

see here for a sample how the insertcommand can be done:

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 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