title: C# & SQL Server stored procedure - Must Declare The Scalar Variable @SellerLocationID
body: <p>My first attempt at creating a stored procedure to be run from C# has produced the following result.</p>
  
  <p>However, on invocation, I get the error </p>
  
  <blockquote>
    <p>Must declare scalar @SellerLocationID</p>
  </blockquote>
  
  <p>I have tried including the statement</p>
  
  <pre><code>declare @SellerLocationID int = 0;
  </code></pre>
  
  <p>Both within and outside of the stored procedure.</p>
  
  <p>I receive the same error in either case.</p>
  
  <p>What do I need to do to resolve this error?</p>
  
  <p>C# (Invoking Code)</p>
  
  <pre><code> var sqlUserName = new SqlParameter("@SellerLocationID", SellerLocationID);
  
  var results = unitofwork.DBContext().Database
                                  .SqlQuery&lt;dynamic&gt;
                                  ("Exec GetClientOrdersForSupplier @SellerLocationID", SellerLocationID).ToList();
  </code></pre>
  
  <p>T-SQL:</p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER PROCEDURE [dbo].[GetClientOrdersForSupplier]
      @SellerLocationID int
  AS
  BEGIN
      SET NOCOUNT ON;
  
      SELECT 
          l.LocationName, u.UserID, u.FirstName, u.LastName, 
          MAX(o.OrderSubmittedDate) as LastOrderPlaced
      FROM
          sw.Locations l
      JOIN 
          sw.Users u ON u.locationid = l.locationid 
      LEFT JOIN
          sw.locationproviders lp ON u.LocationID = lp.BuyerLocationID 
      LEFT JOIN
          sw.orders o ON o.CreatedUserID = u.UserID
      WHERE
          lp.sellerlocationid = @SellerLocationID
      GROUP BY 
          l.LocationName, u.UserID, u.FirstName, u.LastName
      ORDER BY
          UserID
  END
  </code></pre>