First, I want to apologize because my question involves c#, but I can't figure out whether the source of the error is from the c# side or from the SQL Server side.
I have the following stored procedure:
CREATE PROCEDURE [dbo].[AddProject]
@email varchar(320),
@project varbinary(max),
@ProjectName varchar(32)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO Projects (Project, CreationDate, ProjectName) VALUES (@project, GETDATE(), @ProjectName);
DECLARE @ID INT = SCOPE_IDENTITY();
INSERT INTO ProjectsUsers VALUES (@email, @ID);
SELECT @ID;
END
I am trying to call the stored procedure using the function:
public static int InsertNewProjectIntoDB(string Email, string ProjectName, EmployeeTree employeeTree)
{
const string SQL_SP = "dbo.AddProject";
using (var conn = new SqlConnection(ConnectionString))
using (var command = new SqlCommand(SQL_SP, conn)
{
CommandType = CommandType.StoredProcedure
})
{
command.Parameters.AddWithValue("@email", Email);
command.Parameters.AddWithValue("@project", ObjectToByteArray(employeeTree));
command.Parameters.AddWithValue("@ProjectName", ProjectNameq);
conn.Open();
return (int)(command.ExecuteScalar());
}
}
When I do it, I get the error: "Procedure or function 'AddProject' expects parameter '@email', which was not supplied."
But as you can see from the code, I did supply the "email" parameter, yet I got the error.
What am I doing wrong?