title: Parameter not passing into SQL Server stored procedure
body: <p>I need help with this; seems straightforward but I just can't figure it out.</p>
  
  <p>My code:</p>
  
  <pre><code>    public DataTable GetUserAssociatedModules(string UserEmail)
      {
          // retrieve module titles from Module table to be passed to ddlModules in Student.Master
          try
          {
              SqlCommand getModules = new SqlCommand("GetUserAssociatedModules", con);
              getModules.Parameters.AddWithValue("@userEmail", UserEmail);
  
              SqlDataReader dr;
              dr = getModules.ExecuteReader();
  
              //DataTable dt = new DataTable();
              dt.Columns.Add("moduleTitle");
              dt.Load(dr);
              return dt;
          }
          catch (Exception ex)
          {
              HttpContext.Current.Response.Write("Exception: " + ex.Message + ", CourseDAO.GetModules()");
              return null;
          }
          finally
          {
              // close database connection
              if (con != null)
              {
                  con.Close();
              }
          }
      }
  </code></pre>
  
  <p>I keep getting an exception:</p>
  
  <blockquote>
    <p><em>Procedure or function 'GetUserAssociatedModules' expects parameter '@userEmail', which was not supplied.</em></p>
  </blockquote>
  
  <p>I put a a watch on <code>UserEmail</code>; it's passing the value down from the UI as it should but the datareader remains null...</p>
  
  <p>I've checked my SQL; it executes OK.</p>
  
  <p>I've double and triple checked to ensure stored procedure name called in code matches the procedure in the database and that the parameter name in the code matches the one in the procedure...</p>
  
  <p>The procedure...</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[GetUserAssociatedModules]
      @userEmail nvarchar(MAX)
  AS
  BEGIN
      SELECT 
          [dbo].[Module].[moduleId],[moduleTitle] 
      FROM 
          [dbo].[Module] 
      INNER JOIN 
          [dbo].[ModuleUser] ON [dbo].[Module].[moduleId] = [dbo].[ModuleUser].[moduleId]
      WHERE 
          [dbo].[ModuleUser].[userId] = (SELECT [userId]
                                         FROM [dbo].[User]
                                         WHERE [eMail] = @userEmail)
      ORDER BY 
          [moduleTitle] ASC
  END
  </code></pre>