I need help with this; seems straightforward but I just can't figure it out.
My 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();
}
}
}
I keep getting an exception:
Procedure or function 'GetUserAssociatedModules' expects parameter '@userEmail', which was not supplied.
I put a a watch on UserEmail; it's passing the value down from the UI as it should but the datareader remains null...
I've checked my SQL; it executes OK.
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...
The procedure...
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