0

How can I send parameter for IN function. When I add "aa3,b4,gf2". Its always coming null. But my table has aa3 and b4.

  commandx.StoredProcedure = "GET_TEST";
  commandx.AddParameter("@names", "aa3,b4,gf2"); 



 ALTER PROCEDURE [dbo].[GET_TEST]
 @names varchar(15)
 AS

SELECT id,name FROM TBL_TEST where atm_kodu IN (@names)

RETURN @@ROWCOUNT
user3583183
  • 91
  • 1
  • 5

2 Answers2

1

You need to put the quotes on parameters for the IN clause, see example:

commandx.StoredProcedure = "GET_TEST";
  commandx.AddParameter("@names", "'aa3','b4','gf2'"); 



 ALTER PROCEDURE [dbo].[GET_TEST]
 @names varchar(15)
 AS

SELECT id,name FROM TBL_TEST where atm_kodu IN (@names)

RETURN @@ROWCOUNT
Dusan
  • 791
  • 5
  • 16
0

It is because you need to have a quotes around names string. Like

commandx.AddParameter("@names", "'aa3','b4','gf2'"); 

If you have a string composed of your multiple values such as

commandx.AddParameter("@names", "aa3,b4,gf2"); 

Then You might need a function that will explode your string using a delimiter (split at comma or whatever character is splitting your string and put vales in single quotes)

Pawan
  • 1,704
  • 1
  • 16
  • 37