How do we return a value from a stored procedure
here is my sp looks like:
create proc dbo.spInsertGroup
@ID uniqueidentifier
@GroupName varchar(100),
@IsActive bit
AS
BEGIN
insert into tblGroup
values(@ID, @GroupName, @IsActive)
Select @@IDENTITY AS ID
END
based on the return value i want to show the user some kind of feedback wether the save was successfull or failed.
public void AddInquiry(Inquiry inq)
{
using (var transaction = new TransactionScope())
{
using (MyDataContext dc = conn.GetContext())
{
var results = dc.spInquiry_Insert(......).ToList();
transaction.Complete();
var returnValue = (int)results.ReturnValue;
// note that ReturnValue is of type object and must be cast.
}
}
}
error:
Error 39 ‘System.Collections.Generic.List’
does not contain a definition for
‘ReturnValue’ and no extension method
‘ReturnValue’ accepting a first
argument of type
‘System.Collections.Generic.List’
could be found (are you missing a
using directive or an assembly
reference?)
try:
You are getting that error because you are calling the .ToList() so the var results is of type List<> that has no ReturnValue property.
If you can’t see the ReturnValue property, maybe you need to update the method generated by LINQ