1

I am using C# to add extended properties to the tables in my database. When I use a SQL editor, this code works, as each statement is on a new line. However, when creating the command as a string in C#, I get 'Incorrect syntax near GO' twice in the same error message. How can I write this out so that c# executes it on seperate lines or in the correct syntax?

USE UserList; 
GO EXEC sys.sp_addextendedproperty 
@name = N'Description', 
@value=N'some text', 
@level0type=N'SCHEMA', @level0name=N'dbo', 
@level1type=N'TABLE', 
@level1name=N'table_name'
GO
barnacle.m
  • 2,070
  • 3
  • 38
  • 82
  • 4
    `GO` is a hint for SQL Management Studio, see http://stackoverflow.com/questions/40814/how-do-i-execute-a-large-sql-script-with-go-commands-from-c and others – Alex K. Feb 12 '14 at 16:35
  • Also, using @ before your string literal lets you use multiline queries without adding special characters. – Tarec Feb 12 '14 at 16:37
  • Took out the GO and now it works flawlessly, thanks guys. Make an answer and I'll accept it. – barnacle.m Feb 12 '14 at 16:48

1 Answers1

1
USE UserList; 
GO         --<-- Go key word should be on it own in a line nothing before or after 

EXEC sys.sp_addextendedproperty 
@name = N'Description', 
@value=N'some text', 
@level0type=N'SCHEMA', @level0name=N'dbo', 
@level1type=N'TABLE', 
@level1name=N'table_name'
GO
M.Ali
  • 67,945
  • 13
  • 101
  • 127