E
Ed Dror
Hi there,
I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro.
I have a Price page (my website require login) with GridView with the
following columns
PriceID, Amount, Approved, CrtdUser and Date
And Edit and Delete buttons
I created a function to retrive the current user
Protected Function GetUserName() As String
Return User.Identity.Name
End Function
And on SQLDatasource1 I added
Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles
SqlDataSource1.Updating
e.Command.Parameters("@CrtdUser").Value = GetUserName()
End Sub
I converted the CrtdUser into a template and changed the Field binding
from crtdUser to GetUserName() function
Also I created a Trigger for Update which basically insert updated records
into a log table from Inserted = NEW and deleted = Old
Everything works fine
I also created a trigger for Delete look like this
CREATE TRIGGER [dbo].[tr_Price_Delete]
ON [dbo].[Price]
AFTER DELETE
AS
BEGIN
SET NOCOUNT ON;
Insert into dbo.PriceArchive
Select
'New','D',
Price_ID,Amount,Store_ID,BSP,ALC_ID,GN_ID,Approved,CrtdUser,GetDate()
From Deleted
END
Because the delete trigger is from deleted every times when user delete
record the log table populated with the original user name that create the
record
I also changed the label on the GridView with GetUserName() so now it show
only the current user name (overrite the acual record) but it dsen't
populate the table with current user name
The crtdUser show old values insted of new.
How do I retreived the current user on delete method whith this GridView
control?
Thanks,
Ed Dror
I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro.
I have a Price page (my website require login) with GridView with the
following columns
PriceID, Amount, Approved, CrtdUser and Date
And Edit and Delete buttons
I created a function to retrive the current user
Protected Function GetUserName() As String
Return User.Identity.Name
End Function
And on SQLDatasource1 I added
Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles
SqlDataSource1.Updating
e.Command.Parameters("@CrtdUser").Value = GetUserName()
End Sub
I converted the CrtdUser into a template and changed the Field binding
from crtdUser to GetUserName() function
Also I created a Trigger for Update which basically insert updated records
into a log table from Inserted = NEW and deleted = Old
Everything works fine
I also created a trigger for Delete look like this
CREATE TRIGGER [dbo].[tr_Price_Delete]
ON [dbo].[Price]
AFTER DELETE
AS
BEGIN
SET NOCOUNT ON;
Insert into dbo.PriceArchive
Select
'New','D',
Price_ID,Amount,Store_ID,BSP,ALC_ID,GN_ID,Approved,CrtdUser,GetDate()
From Deleted
END
Because the delete trigger is from deleted every times when user delete
record the log table populated with the original user name that create the
record
I also changed the label on the GridView with GetUserName() so now it show
only the current user name (overrite the acual record) but it dsen't
populate the table with current user name
The crtdUser show old values insted of new.
How do I retreived the current user on delete method whith this GridView
control?
Thanks,
Ed Dror