title: MSSQL pass parameter to In query in C#
body: <p><strong>What I want to do :</strong>
  Pass this parameter <code>'TV','OV','CK'</code> as a single string into Stored Procedure (GetAllDataViaInQuery)</p>
  
  <pre><code>CREATE PROCEDURE GetAllDataViaInQuery @param varchar(240)
  AS
  BEGIN
  SELECT TOP 100 [Model_No]
        ,[AppCode]
        ,[Model]
  FROM [S_ModelMaster] where AppCode in (@param)  
  END
  </code></pre>
  
  <p><strong>Then</strong></p>
  
  <p>I need to Pass parameter value via C# application as a single parameter.Because some time in values are may be vary.</p>
  
  <p>Ex : <code>string paramValue = "TV,OV,CK";</code></p>
  
  <p>Then I wrote this C# code snippet.</p>
  
  <pre><code>using (SqlConnection con = new SqlConnection(Properties.Settings.Default.Setting))
              {
                  try
                  {
                      //hard coded parameter values
                      string paramValue = "TV,OV,CK";
                      con.Open();
                      DataSet ds = new DataSet();
                      SqlCommand com = new SqlCommand("GetAllDataViaInQuery", con);
                      com.CommandType = CommandType.StoredProcedure;
                      SqlParameter param = new SqlParameter("@param", paramValue);
                      com.Parameters.Add(param);
  
                      SqlDataAdapter adp = new SqlDataAdapter(com);
                      adp.Fill(ds);
                      dataGridView1.DataSource = ds.Tables[0];
                  }
                  catch (Exception ex)
                  {
                      MessageBox.Show(ex.Message);
                  }
              }
  </code></pre>
  
  <p>But this is not work yet.
  Then I execute Stored Procedure manually with <strong>SSMS</strong>.</p>
  
  <p><a href="https://i.stack.imgur.com/vblaM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vblaM.jpg" alt="enter image description here"></a></p>
  
  <pre><code>DECLARE @return_value int
  
  EXEC    @return_value = [application].[GetAllDataViaInQuery]
          @param = N'TV,OV,CK'
  
  SELECT  'Return Value' = @return_value
  </code></pre>
  
  <p><strong>But it's NOT WORKED!</strong></p>
  
  <p>Then I try it in <code>sql query</code></p>
  
  <pre><code>SELECT TOP 100 [Model_No]
        ,[AppCode]
        ,[Model]
  FROM [S_ModelMaster] where AppCode in ('TV','OV','CK')  
  </code></pre>
  
  <p>And it's work.So what is the correct way to pass parameter to <code>IN</code> query in C#?</p>