471,350 Members | 1,928 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Running an entire SQL Script from C#

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.
Nov 29 '05 #1
7 1388
Append them all together into a single string and use them as your
CommandText property with CommandType set to Text (on the xxxCommand object.
"farsad nasseri" <fa***********@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
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.

Nov 29 '05 #2

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)?
"Martin Robins" wrote:
Append them all together into a single string and use them as your
CommandText property with CommandType set to Text (on the xxxCommand object.
"farsad nasseri" <fa***********@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
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.


Nov 30 '05 #3
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

farsad nasseri wrote:
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)?
"Martin Robins" wrote:

Append them all together into a single string and use them as your
CommandText property with CommandType set to Text (on the xxxCommand object.
"farsad nasseri" <fa***********@discussions.microsoft.com> wrote in message
news:3E**********************************@micros oft.com...
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.


Nov 30 '05 #4
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"farsad nasseri" <fa***********@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
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.

Nov 30 '05 #5
Listen that is really uncalled for take a chill pill man.

----------------------------------
http://community.ihostasp.net
ASP.NET Developer Community
Nov 30 '05 #6
> 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

"ship261" <st*****@m-s-n-dot-net.no-spam.invalid> wrote in message
news:l8********************@giganews.com...
Listen that is really uncalled for take a chill pill man.

----------------------------------
http://community.ihostasp.net
ASP.NET Developer Community

Nov 30 '05 #7
Yup I have to agree .. no idea what your talking about .. hehe

Reply to wrong thread me thinks ;)

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

----------------------------------
http://community.ihostasp.net
ASP.NET Developer Community

Dec 1 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Sticks | last post: by
1 post views Thread by Andrew Chalk | last post: by
12 posts views Thread by Troy | last post: by
reply views Thread by Titof | last post: by
2 posts views Thread by Benjamin Rutt | last post: by
13 posts views Thread by wattersmt | last post: by
24 posts views Thread by Mark | last post: by
22 posts views Thread by V S Rawat | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.