{"Incorrect syntax near the keyword 'TRIGGER'."}
-
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
-
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
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