Running an entire SQL Script from C#

G

Guest

Hi

I have written a small transformation routine that converts my XML file into
a bunch of Insert statements in another file. The file will be in the
following format but much longer:

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('lasfgasd ');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('asgasg');

INSERT INTO lockbox_refid (lockbox_refid)
VALUES ('afgsasg');

How can I possibly run this entire script from inside of my script???
Assuming I can already make my connection to the SQL Server Database.
 
M

Martin Robins

Append them all together into a single string and use them as your
CommandText property with CommandType set to Text (on the xxxCommand object.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


You do not need to run it as a single script, at least the snip you gave,
you could just simply execute it one by one, of course the performance will
be lower than if you concatenate all the script in a single string and pass
it to the server.

Now if you have a REAL big script ( like 10K inserts ) having it as a
single command is not practical.

cheers,
 
G

Guest

I'm sorry if this is a simple question.. but how do I append them all into
on string?
and is that the only way? is there no way of committing or executing a
script (*.sql)?
 
S

Simon

Yes you could use a StreamReader to read the sql from the file and then
set it as the commandText of the Command object.

Simon
 
K

Kevin Spencer

Listen that is really uncalled for take a chill pill man.

I agree. Whoever the heck it is you're talking to, whatever the heck you're
talking about, he or she should take a chill pill. Seriously. Dude.

--

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 
S

Simon

Yup I have to agree .. no idea what your talking about .. hehe

Reply to wrong thread me thinks ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top