Link to home
Start Free TrialLog in
Avatar of escap-fss
escap-fss

asked on

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

Hi,

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.

Thanks.
Rizwan.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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.
Avatar of escap-fss
escap-fss

ASKER

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.
Thanks.

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial