Passing multiple records to a stored procedure....

G

Guest

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
 
I

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

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,
 
K

Kevin Yu [MSFT]

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."
 

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