我有以下列表我可以将列表传递给存储过程吗?
ID | DESC | PRICE
10 | SHOE | 5000
11 | LACE | 3000
12 | GAME | 2000
13 | TOAD | 3000
我现在通过各行的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));
...
}
}
那么,如何通过列表存储过程?
你能请注明您所使用的SQL Server的版本,每当你问一个有关SQL Server的问题? (通过您以前的问题花了很长时间才确定您至少使用了SQL Server 2008.) – 2012-02-23 04:07:20