【发布时间】:2013-08-09 21:48:17
【问题描述】:
我有一个接受 int[] (userIDs) 和 int (groupID) 作为参数的方法。然后它运行存储过程并将数据插入到数据库中
For example:
if userIDs=[1,2,3] and groupID=4,
then I want the following data to be inserted into the DB
userID groupID
1 4
2 4
3 4
我有两个解决这个问题的方法。第一个是编写一个将单个记录插入数据库的存储过程。在method()中,我会循环遍历int[]并调用存储过程n次
method()
for (int i =0; i< userID.length; i++){
// call stored procedure to insert a single record
}
第二种解决方案是将int[]和int作为参数传递给存储过程,并在存储过程中进行循环。
哪种方法更好? (如果它的第二个解决方案更好,有人可以提供在存储过程中处理 int[] 的指导)
【问题讨论】:
标签: c# asp.net-mvc stored-procedures insert