Running an entire SQL Script from C#

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
Append them all together into a single string and use them as your
CommandText property with CommandType set to Text (on the xxxCommand object.
 
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,
 
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)?
 
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
 
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
 
Yup I have to agree .. no idea what your talking about .. hehe

Reply to wrong thread me thinks ;)
 
Back
Top