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

前端 未结 6 1629
走了就别回头了
走了就别回头了 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:03

    As was mentioned in a comment, Erland Sommarskog wrote a series of articles on this topic (linked-to below). The articles are very thorough and can serve as reference material. While they are specific to SQL Server (T-SQL), some of the techniques mentioned might also work for other RDBMS (such as using an XML data type):

    • Arrays and Lists in SQL Server 2008 Using Table-Valued Parameters:

      • Table-Valued Parameters (TVPs)
    • Arrays and Lists in SQL Server 2005 and Beyond When TVPs Do Not Cut it:

      • string serialization and de-serialization of scalar values
      • SQLCLR
      • passing structured list data via the XML data type
      • Dynamic SQL
    • Arrays and Lists in SQL Server 2000 and Earlier

提交回复
热议问题