title: Winforms: How to query a database with a sql function using SqlCommand?
body: <p>I have a method which takes a single string parameter (ID).</p>
  
  <p>I want to use <code>SqlCommand</code> to return a <code>DataTable</code> of results from a query. I'm trying to call a table function from my database (Sql Server) in the query and pass in my ID parameter. The contents of this <code>DataTable</code> will then populate a Combobox. Here's what I have so far...</p>
  
  <pre><code> public string populateCompanyTransSellingEntityLookUp(string BlockId)
      {
          string _sql = "";  
  
          SqlCommand _comm = new SqlCommand();
          _comm.Parameters.AddWithValue("(@block_id", BlockId);
          _comm.CommandText = "SELECT [name] FROM dbo.fnGetBlockCompanyWIList(@block_id) ORDER BY [name]; ";
          _comm.Connection = _conn;
          _comm.CommandTimeout = _command_timeout;
  
          DataTable dt = new DataTable();
          try
          {
              SqlDataReader myReader = _comm.ExecuteReader();
              dt.Load(myReader);
          }
          catch (Exception)
          {
  
              throw;
          }
  
          Combo.DataSource = dt;
          return _sql;                
      }
  </code></pre>
  
  <p>But i'm getting a error, "Must declare scalar variable '@block_id'". why?</p>