3
Reply

Executing SQL scripts from C#

evanwang

evanwang

Nov 23 2004 9:16 AM
2k
Is there any programmatic way to execute a sql script from C#? I'm using SQL Server and I do not want to use osql.exe. Here is an example: CREATE TABLE... GO CREATE TABLE... GO CREATE CONSTRAINT... GO INSERT DATA... GO I tried reading the file and setting the CommandText in the SqlCommand object, but since the GO needs to be in a separate line when executing, SQL Server gives an error. I tried some various newline characters, but none worked. Any thoughts? Thanks, Evan

Answers (3)