Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. {"Incorrect syntax near the keyword 'TRIGGER'."}

{"Incorrect syntax near the keyword 'TRIGGER'."}

Scheduled Pinned Locked Moved Database
databasehelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 4005525
    wrote on last edited by
    #1

    Hi I have created a Trigger Statement and assigned to CommandText property of sqlCommand.While Try to Execute using command.ExecuteNonQuery() it throws an exception like {"Incorrect syntax near the keyword 'TRIGGER'."} Created Trigger Statement: CREATE TRIGGER SampleTrigger ON dbo.sample AFTER INSERT AS begin SET NOCOUNT ON DECLARE @Name AS nvarchar(50) SELECT @Name= i.Name from inserted i DECLARE @Address AS nvarchar(50) SELECT @Address= i.Address from inserted i insert into triggertest(statusID,FieldName,FieldValue) values( 25,'Name',@Name) insert into triggertest(statusID,FieldName,FieldValue) values( 25,'Address',@Address) end Can anyone help me? Thanks in advance Sri

    C 1 Reply Last reply
    0
    • U User 4005525

      Hi I have created a Trigger Statement and assigned to CommandText property of sqlCommand.While Try to Execute using command.ExecuteNonQuery() it throws an exception like {"Incorrect syntax near the keyword 'TRIGGER'."} Created Trigger Statement: CREATE TRIGGER SampleTrigger ON dbo.sample AFTER INSERT AS begin SET NOCOUNT ON DECLARE @Name AS nvarchar(50) SELECT @Name= i.Name from inserted i DECLARE @Address AS nvarchar(50) SELECT @Address= i.Address from inserted i insert into triggertest(statusID,FieldName,FieldValue) values( 25,'Name',@Name) insert into triggertest(statusID,FieldName,FieldValue) values( 25,'Address',@Address) end Can anyone help me? Thanks in advance Sri

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Since you don't show the way you build up the string, my guess is that the string sent to the SqlCommand is not exactly the one shown. For example:

      string sql = "CREATE TRIGGER SampleTrigger" +
      "ON dbo.sample";

      will actually result in a string that reads:

      CREATE TRIGGER SampleTriggerON dbo.sample

      Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) - (part 3) My website | Blog

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups