Entity Framework Code First Stored Proc Incorrect Syntax / Must Declare Scalar Varible
Working on getting a stored procedure to execute from a web app. I can verify that the values are being populated like the should but I either get one of two errors. Here is the re
Solution 1:
// Message = "Must declare the scalar variable \"@OldCompany\"." - have tried with both the parameter1 and parameter1.Value, parameter2 and parameter2.Valuepublic virtual intusp_TransferRecords(int oldCompany, int newCompany)
{
SqlParameterparameter1=newSqlParameter("OldCompany", oldCompany);
SqlParameterparameter2=newSqlParameter("NewCompany", newCompany);
return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreCommand("usp_CopyRecord @OldCompany, @NewCompany", parameter1, parameter2);
}
Your error message tells you the problem.
"Must declare the scalar variable \"@OldCompany\"."
"@OldCompany" != "OldCompany"Solution 2:
Here is what eventually
// Workingpublic virtual intusp_TransferRecords(int oldCompany, int newCompany)
{
var@params = newSqlParameter[]
{
newSqlParameter("OldCompany", oldCompany),
newSqlParameter("NewCompany", newCompany)
};
return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreCommand("usp_TransferRecords @OldCompany, @NewCompany", @params);
}
Post a Comment for "Entity Framework Code First Stored Proc Incorrect Syntax / Must Declare Scalar Varible"