I need to create multiple records in sqlserver, each with the same value in column A, but with a unique value in column B. I have values ββfor column B in the array.
I am using VS2008, aspnet, C # 3.5, sqlserver 2005.
I'm better
Option 1.
Making 1 call to a stored procedure in sqlserver from c # code and then doing all the processing in the stored procedure in tsql?
This involves combining all the values ββin the C # array into a single line with comma-delimited ones and passing the string to tsql as a parameter, then looping and breaking the string into separate values ββand inserting a record for each of them, all inside a stored procedure.
From what I see, this will require easy rollback if necessary, but very awkward line processing in tsql.
Or
Option 2
Running a loop in C # and passing data in the form of sqlparams from a C # one record at a time to a stored process to insert each record.
I.e., foreach (int key in myarray) ... insert record
I could make this code in a dream, but how can I roll back if something happened in the middle of processing? And should I do a loop inside in one connection. Open and connection.close?
Anyone have other options for this?
Lill lansey
source share