我有以下清单
ID | DESC | PRICE
10 | SHOE | 5000
11 | LACE | 3000
12 | GAME | 2000
13 | TOAD | 3000
Run Code Online (Sandbox Code Playgroud)
我现在正在foreach循环中传递单个行,并且始终建立新连接,这看起来非常规,但我希望有更快的方法.
这是我的代码.
foreach(var item in tempList)
{
using (connection)
{
SqlCommand command = new SqlComman("StoredProc", connection);
command.Parameters.Add(new SqlParameter("id", item.id));
command.Parameters.Add(new SqlParameter("desc", item.desc));
command.Parameters.Add(new SqlParameter("price", item.price));
...
}
}
Run Code Online (Sandbox Code Playgroud)
那么如何将列表传递给存储过程呢?