0
我有一個存儲過程,我想在該存儲過程中返回輸出值,並在我通過實體框架訪問它的應用程序上訪問它。只能通過RowsAffectedParameter屬性映射輸出參數
我的存儲過程:
ALTER Procedure [dbo].[Insert_StudentDetails]
(
@Name varchar(150),
@City varchar(150),
@ReturnValue int OUT
)
as
Begin
--Declare
if NOT exists(Select Name from Student
WHERE [email protected]
AND [email protected])
begin
Insert into Student(Name, City)
values(@Name, @City)
set @ReturnValue=1
end
else
begin
set @ReturnValue=0
end
select @ReturnValue
End
現在後右鍵點擊EDMX文件中的表格它顯示爲以下幾點:
當我導入功能,我選擇沒有在返回。
我通過下面的代碼訪問它:
public bool insertstudentdata(Student student)
{
using (CollegeDataEntities context = new CollegeDataEntities())
{
ObjectParameter ReturnedValue = new ObjectParameter("ReturnValue", typeof(int));
context.InsertStudentData(student.Name, student.City, ReturnedValue);
if (Convert.ToInt32(ReturnedValue) == 1)
{
return true;
}
else
{
return false;
}
}
}
在運行時,它顯示了以下異常:
錯誤列表,下面的異常也即將: