title: SQL Server : executing stored procedure problems
body: <p>I am trying to execute a stored procedure I keep getting an error:</p>
  <blockquote>
  <p>Procedure or function 'dynamictable' expects parameter '@tablename', which was not supplied</p>
  </blockquote>
  <p>Can you please fix my code?</p>
  <pre><code>conn.Open();    
  SqlCommand search = new SqlCommand(&quot;dbo.dynamictable&quot;, conn);
  search.CommandType = CommandType.StoredProcedure;
  search.Parameters.Add(new SqlParameter(&quot;@tablename&quot;, table));
  search.Parameters.Add(new SqlParameter(&quot;width&quot;, housewidth.ToString()));
  </code></pre>
  <p>Here is the query if it may help you help me:</p>
  <pre><code>CREATE PROCEDURE dynamictable
      (@tablename nvarchar(100), @width nvarchar(50))
  AS
  BEGIN
      DECLARE @SQL nvarchar(max)
  
      SELECT @SQL = 'SELECT * FROM [' + @tablename+ '] WHERE [Width] = '+ @width;
  
      EXEC sp_executesql @SQL
  END
  </code></pre>