Passing a SQL parameter to an IN() clause using typed datasets in .NET

后端 未结 8 2009
别跟我提以往
别跟我提以往 2020-11-28 10:31

First apologies as there are similar questions on this site, but none of them answer this problem directly.

Im using typed datasets in VS 2010. I create a TableAdapt

8条回答
  •  失恋的感觉
    2020-11-28 11:24

    I tried a workaround for using string "contains" concept in SQL way:

    In your case, change the SQL -

    Original:

    SELECT * from Table WHERE ID IN(@IDs)

    Become:

    SELECT * from Table WHERE CharIndex(','+Cast(ID As Varchar(10))+',',@IDs) > 0

    With .net code -

    Original:

    TableAdapter.Fill(MyDataTable,"1,2,3")

    Become:

    TableAdapter.Fill(MyDataTable,",1,2,3,")

提交回复
热议问题