can i pass a List into a SqlCommand as a paramter?
DELETE FROM MyTable WHERE Key IN @MyParam
command.Parameters.AddValue("MyParam",MyList);
i realize i could just loop over the list but i was looking for a cleaner solution.
can i pass a List into a SqlCommand as a paramter?
DELETE FROM MyTable WHERE Key IN @MyParam
command.Parameters.AddValue("MyParam",MyList);
i realize i could just loop over the list but i was looking for a cleaner solution.
No, you can't in the current form
There are several options using UDFs or XML or dynamic SQL to pass in lists.
The most comprehensive article on how to do this is "Arrays and Lists in SQL Server 2005 and Beyond" by Erland Sommarskog
Pass them as a table type parameter,
CREATE TYPE dbo.CategoryTableType AS TABLE
( CategoryID int )
then consume it in your procedure
CREATE PROCEDURE usp_UpdateCategories
(@tvpNewCategories dbo.CategoryTableType READONLY)
and do stuff like
delete from dbo.Categories where id in (select CategoryID from @tvpNewCategories) ;