Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
var BranchIDParam = new ObjectParameter("BranchIDOut", typeof(int));




C#
     var resultBranchInsert = db.Database.SqlQuery<int>
("exec TempspInsertBranch @Code={0},@Name={1},@branchTypeID={2},@AddressLine1={3},@AddressLine2={4},@CityID={5},@StateID={6},@RegionID={7},@CountryID={8},@ZipCode={9},@Landmark={10},@PhoneNo1={11},@PhoneNo2={12},@PhoneNo3={13},@FaxNo1={14},@FaxNo2={15},@EmailAddress1={16},@EmailAddress2={17},@CreatedBy={18},@CreatedUser={19},@BranchIDOut={20}",
            Code,Name,BranchTypeID,Add1,Add2,CityID,StateID,RegionID,CountryID,ZipCode,Landmark,Phone1,Phone2,"",Fax1,Fax2,Email1,Email2,UserID,User,BranchIDParam);
            
int BranchID =BranchIDParam.Value.ToString()==""?0:Convert.ToInt32(BranchIDParam.Value.ToString());



SP Declaration : @BranchIDOut int OUTPUT
After Insert SP : SELECT @BranchIDOut=SCOPE_IDENTITY()
Posted

1 solution

You can do this by marking the parameter as the OUTPUT parameter.
Here[^] is an example -
EXECUTE Sales.uspGetEmployeeSalesYTD<br />
    N'Blythe', @SalesYTD = @SalesYTDBySalesPerson OUTPUT;


However, it is much neater to do this using command parameters (and safer as well) - How to return Output parameter from Stored Procedure in ASP.Net using C# and VB.Net[^].
 
Share this answer
 
Comments
Abrar Kazi 14-Jan-16 6:49am    
It would be great if u would help me modify the above code.
Also the links provided are not for MVC.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900