c# - asp.net stored procedure insert multiple pairs of data into the DB -


i have method accepts int[] (userids) , int (groupid) parameters. runs stored procedure , insert data db

for example: if userids=[1,2,3] , groupid=4,  want following data inserted db userid    groupid 1            4 2            4 3            4  

i have 2 solutions problem. first 1 write stored procedure insert single record db. in method(), loop through int[] , call stored procedures n times

method() (int =0; i< userid.length; i++){     // call stored procedure insert single record } 

the second solution pass int[] , int parameters stored procedures , looping in stored procedure.

which way better solution? ( if 2nd solution better, can provide guidance on handling int[] in stored procedure )

is there reason why don't want use o/r mapper? example looks server / code-behind , can use entity framework (or other) insert new values. if can't use them use ( 2nd in posting) approach. it's dangerous, because not within transaction.

you can start entity framework investigation here : http://www.asp.net/entity-framework. if you, reasons, not able use ef consider using transcation scope sql commands ( see http://msdn.microsoft.com/en-us/library/777e5ebh.aspx starting reading )


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -