Monday, 20 January 2014

Simple trigger in sql server 2008 R2

CREATE TRIGGER trig_Insert_Employee
ON Emp
FOR INSERT
AS
Begin
    Insert into dbo.backtable (id, insertdate)   select MAX(id),GETDATE() from Emp
    
End



here
Emp is table name , whenever emp table gets insert the trigger will get fired! 





























insert into Emp(id,name) values(2,'First')


select * from sys.objects where type='TR'

The above query will display the triggers in database. and it holds parent object id.

varbinary to file sql server 2008 R2


declare @IMG varbinary(max)
declare @FileName varchar(max)
declare @ObjectToken INT

set @IMG=(select Binarydata from File_T where ID=3)
--SET @FileName = 'd:\' + replace(replace(replace(replace(convert(varchar,getdate(),121),'-',''),':',''),'.',''),' ','') + '.pdf'
set @FileName='d:\Image1.pdf'
      
       

        EXEC sp_OACreate 'ADODB.Stream', @ObjectToken OUTPUT
        EXEC sp_OASetProperty @ObjectToken, 'Type', 1
        EXEC sp_OAMethod @ObjectToken, 'Open'
        EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @IMG
        EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, @FileName, 2
        EXEC sp_OAMethod @ObjectToken, 'Close'
        EXEC sp_OADestroy @ObjectToken
       
     

enable ole automation sql 2008 r2

sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO

Saturday, 11 January 2014

confirm box for LinkButton in asp.net

<asp:LinkButton ID="lnkMaterialIndentRevise" runat="server" Text="Indent Revise"
                                        OnClientClick="javascript:return confirm('Are you sure you want to revise this indent?')" OnClick="lnkMaterialIndentRevise_Click"></asp:LinkButton>