469,275 Members | 1,805 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Passing multiple records to a stored procedure....

Hi all,
being new to c# I'm trying to find the best way of passing multiple records
to insert into a sql database via a stored procedure.
I'm using visual studio 2005 RC
SQL server 2005 and C# of course.
My scenario is as follows:
I have a multiline textbox with which users can enter numerous items(one per
line) and all are then added to an Arraylist and then seperatly validated
using a Regex.
Once all valid entries are collated I would then like to run a stored
procedure to add them all to the database.

What's the best way of doing this?
I considered running a foreach loop on every single item but thought this
would be too slow. Is it possible to send the entire arraylist to a stored
procedure and execute the entry into the database there?

Any help would be appreciated.

Thanks
Nov 17 '05 #1
2 2836
Hi,

running a loop would work fine, just do not recreate the Command on each
time, just change the value of the parameter

Try this first and if the performance is not good enough then you can think
about other variants, but I would definely give it a try first

cheers,

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

"Paul Hale" <Pa******@newsgroups.nospam> wrote in message
news:11**********************************@microsof t.com...
Hi all,
being new to c# I'm trying to find the best way of passing multiple
records
to insert into a sql database via a stored procedure.
I'm using visual studio 2005 RC
SQL server 2005 and C# of course.
My scenario is as follows:
I have a multiline textbox with which users can enter numerous items(one
per
line) and all are then added to an Arraylist and then seperatly validated
using a Regex.
Once all valid entries are collated I would then like to run a stored
procedure to add them all to the database.

What's the best way of doing this?
I considered running a foreach loop on every single item but thought this
would be too slow. Is it possible to send the entire arraylist to a stored
procedure and execute the entry into the database there?

Any help would be appreciated.

Thanks

Nov 17 '05 #2
Hi Paul,

I agree with Ignacio that you just need to create one Command object.
However, you can also use a DataSet to store the data input from the
TextBoxes. When you need to update data into the database, create a
SqlDataAdapter from the SqlCommand object and issue a SqlDataAdapter.Update.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by shank | last post: by
1 post views Thread by vncntj | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.