-
how to make triggers
hello guys :bigyello:
i just wanted to ask how can i create triggers from code using VB6 or anyother version of VB
i made a command and assinged the trigger script to the command but i didnt work out ! it sounds the commands connot exexute T-SQL scripts
Code:
cmd.ActiveConnection = conn
cmd.CommandText = strTrigger
cmd.Execute
i tried to use all cmd.commandtype but non of them succeed .
adCmdFile,adCmdStoredProc,adCmdTable,adCmdTableDirect,adCmdTableDirect,adCmdText and adCmdUnknown :sick:
i also tried conn.Execute strTrigger :confused:
BTW strTrigger string contains the trigger script
Code:
CREATE TRIGGER [AAA_TR] ON [AAA] FOR INSERT, UPDATE, DELETE
AS
DECLARE @ID AS VARCHAR(100) bla bla bla ...... etc
but its giving me an error on line 1
" Line 1: Incorrect syntax near 'Begin' "
what i'm doing exactly is trying to make triggers to some tables from code and then droping these triggers
if i execute the script from the query analyzer it works fine, but not from the code
can anybody help please please its urgent :confused:
thank you :)
-
Re: how to make triggers
Welcome to the Forums.
From your Enterprize Manager or SQL Management Studio (depends on your version of SQL Server) you can create the trigger manually and then save it, right click on it, select "Script trigger name"..., and copy the sql text for use in your vb program.
Thread Moved
-
Re: how to make triggers
Show us the code that builds the strTrigger text. I suspect that you are missing some spaces or line breaks.