Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to pass List<string> into stored procedure in sql 2005 using c#.
Hamassss 3-Dec-13 4:19am    
List of what ? List of strings ? Then just do foreach(item i in list) and pas it as strings to procedure.
If u have List of some custon objects then u need to decompose it to types DataBase can store and pass it again through some loop

That's actually a lot harder than it sounds, because SQL deosn't have a concept of "lists" or even "arrays".

Depending on exactly what you want to do with the list this might help:
Using comma separated value parameter strings in SQL IN clauses[^] - it deals with processing a commas separated string of vlaues into a temporary table for use in an SQL IN clause, which may go some way to helping you.
Share this answer
Maciej Los 3-Dec-13 11:36am    
may be pass xml as string
and then

-- Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @XmlDocumentHandle OUTPUT, @XmlDocument
-- Execute a SELECT stmt using OPENXML rowset provider.
FROM OPENXML (@XmlDocumentHandle, '/ROOT/Customer/Order/OrderDetail',2)
WITH (OrderID int '../@OrderID',
CustomerID varchar(10) '../@CustomerID',
OrderDate datetime '../@OrderDate',
ProdID int '@ProductID',
Qty int '@Quantity')
EXEC sp_xml_removedocument @XmlDocumentHandle
Share this answer
As Griff has stated in SQL Server 2005 it isn't easy here is an article that discusses using it with SQL 2005[^]
Share this answer
Table-Valued Parameters were introduced in SQL Server 2008 to provide a feature to make it easier to pass "lists" to a SQL Server Stored Procedure. If you have the option to upgrade to a newer version of SQL Server now or in the future, you may want to consider Table-Valued Parameters.

See Table-Valued Parameters in SQL Server 2008 (ADO.NET)[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900