c# - Stored Procedure not tracking column modifications -


i trying create log of database using stored procedure.but problem here is not tracking multiple column updates or modifications.

following stored procedure

alter procedure [dbo].[proc_trackfollowup]      @followup_id int,@followtype nvarchar(50),@contactperson nvarchar(50),      @followdate datetime,@followtime nvarchar(50),@status nvarchar(50),@comment nvarchar(max)            declare @oldfollowup_id int      declare @oldfollowtype nvarchar(50)      declare @oldcontactperson nvarchar(50)      declare @oldfollowdate datetime      declare @oldfollowtime nvarchar(50)      declare @oldstatus nvarchar(50)      declare @oldcomment nvarchar(max)      declare @oldcompanyname nvarchar(50)      declare @audit_action varchar(100)       select @oldfollowup_id=followup_id,@oldcompanyname=companyname,@oldfollowtype=followtype,@oldcontactperson=contactperson,@followdate=followdate,@oldfollowtime=followtime,@oldstatus=status,@oldcomment=comment      followuptable followup_id=@followup_id       update followuptable set followtype=@followtype,contactperson=@contactperson,followdate=@followdate,followtime=@followtime,status=@status,comment=@comment followup_id=@followup_id       if @oldfollowtype<>@followtype      set @audit_action='follow type changed ' + cast(@oldfollowtype varchar) + ' ' + cast(@followtype varchar)         if @oldcontactperson<>@contactperson      set @audit_action='contact person changed ' + cast(@oldcontactperson varchar) + ' ' + cast(@contactperson varchar)       if @oldfollowdate<>@followdate      set @audit_action='follow date changed ' + cast(@oldfollowdate varchar) + ' ' + cast(@followdate varchar)       if @oldfollowtime<>@followtime      set @audit_action='follow time changed ' + cast(@oldfollowtime varchar) + ' ' + cast(@followtime varchar)       if @oldstatus<>@status      set @audit_action='status changed ' + cast(@oldstatus varchar) + ' ' + cast(@status varchar)       if @oldcomment<>@comment      set @audit_action='comment changed ' + cast(@oldcomment varchar) + ' ' + cast(@comment varchar)       insert loggerfollowuptable      (followup_id,companyname,followtype,contactperson,followdate,followtime,status,comment,audit_action,audit_timestamp)       values(@followup_id,@oldcompanyname,@followtype,@contactperson,@followdate,@followtime,@status,@comment,@audit_action,getdate());   

i have given update option in c# form type dropdown passing @type.but whenever select item dropdown , pass stored procedure,it not track modification.even after editing multiple fields in form,i face same issue

please suggest changes stored procedure

thanks

it easier if approached different angle. have table tracks changes more this.

create table [dbo].[loggerfollowuptable](     [logid] [int] identity(1,1) not null,     [tablename] [varchar](50) not null,     [fieldname] [varchar](50) not null,     [recordid] [int] not null,     [oldvalue] [varchar](50) null,     [newvalue] [varchar](50) null,     [datechanged] [datetime] not null ) on [primary]  go 

and in stored proc more (repeat each field)

if @oldfollowtype<>@followtype begin  insert loggerfollowuptable (tablename, fieldname, recordid, oldvalue, datechanged), newvalue) values ('followuptable', 'followtype', @followup_id, cast(@oldfollowtype varchar), cast(@followtype varchar), getdate()) end 

you end row each value changed.

if want stick have need insert after each value test like.....

 if (@oldfollowdate<>@followdate)  begin     select @audit_action='follow date changed ' + cast(@oldfollowdate varchar) + ' ' + cast(@followdate varchar)      insert loggerfollowuptable  (followup_id,companyname,followtype,contactperson,followdate,followtime,status,comment,audit_action,audit_timestamp)   values(@followup_id,@oldcompanyname,@followtype,@contactperson,@followdate,@followtime,@status,@comment,@audit_action,getdate());   end  

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -