Is it possible to send a collection of ID's as a ADO.NET SQL parameter?

前端 未结 6 1628
走了就别回头了
走了就别回头了 2020-11-29 09:16

Eg. can I write something like this code:

public void InactiveCustomers(IEnumerable customerIDs)
{
    //...
    myAdoCommand.CommandText =
              


        
6条回答
  •  一整个雨季
    2020-11-29 10:00

    You can use xml parameter type:

    CREATE PROCEDURE SelectByIdList(@productIds xml) AS
    
    DECLARE @Products TABLE (ID int) 
    
    INSERT INTO @Products (ID) SELECT ParamValues.ID.value('.','VARCHAR(20)')
    FROM @productIds.nodes('/Products/id') as ParamValues(ID) 
    
    SELECT * FROM 
        Products
    INNER JOIN 
        @Products p
    ON    Products.ProductID = p.ID
    

    http://weblogs.asp.net/jgalloway/archive/2007/02/16/passing-lists-to-sql-server-2005-with-xml-parameters.aspx

提交回复
热议问题