Results 1 to 3 of 3

Thread: how to make triggers

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    1

    how to make triggers

    hello guys
    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


    i also tried conn.Execute strTrigger

    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
    thank you

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width