Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Here I am trying to post some data to DB and at the time my WebApi is accepting the value from angular and to passing data to DB, the data successfully saved. but my problem is at the saving time my Stored procedure is passing an out parameter to WEB API, Then how can i get the out parameter from WebAPI to my angular 4 app? and am new in angular and web API so in my question have any problem please pardon me


What I have tried:

MY SQL Code is
   

    CREATE PROCEDURE storedprocedurename
    (@.....,
    @....,
    @....,
    @Schid int,
     @TransactionId int OUTPUT
    )
    .................
    ................
    set @TransactionId= @Schid
    insert into tbl name(.....)
    (@.....,
    @.....)

My API is

    public class StockcountheaderController : ApiController
    {
        private adminv2Entities enqentities = new adminv2Entities();
        HttpSessionState session = HttpContext.Current.Session;
        [HttpPost]
        public void Stock([FromBody] List<spGetNewStockCountHeader_Result> jsonvalues)
        {
            foreach (spGetNewStockCountHeader_Result Datastock in jsonvalues)
            {
                ObjectParameter TransactionId = new ObjectParameter("TransactionId", typeof(Int32));
                spGetNewStockCountHeader_Result Stockobject = new spGetNewStockCountHeader_Result();
                Stockobject.UserID = Datastock.UserID;
                Stockobject.created = Datastock.created;
                Stockobject.CompanyID = Datastock.CompanyID;
                Stockobject.modified = Datastock.modified;
                Stockobject.modifieduserid = Datastock.modifieduserid;
                Stockobject.confirm = Datastock.confirm;
                Stockobject.ShopId = Datastock.ShopId;
                if (TransactionId.Value != null)
                {
                   session["myTransID"] = (int)TransactionId.Value;
                }
                enqentities.spGetNewStockCountHeader(Datastock.UserID, Datastock.created,
                Datastock.CompanyID, Datastock.modified, Datastock.modifieduserid, Datastock.confirm,
                Datastock.ShopId, TransactionId);
            }
        }


Typescript file is

     TransactionId:number=1;
            this.header = new IHeaderstock(this.userid, this.created, this.CompanyID, this.modified, this.modifieduserid, this.confirm, this.shopid,this.TransactionId);
        this.headeritems.push(this.header);

              onClick() {
               this._enqService.CatchHeaderDetail(this.headeritems)
            .subscribe(value => {
                if (typeof value !== 'undefined' && value != null) {
                    value.forEach(header => {
                        this.headeritems.push(this.header)
                    });
                }
            },
                error => {
                    console.error(error);
                    this.statusMessage = "Problem with the service.Please try again after sometime";
                });
And my service.ts is 

        CatchHeaderDetail(stock: any)
        : Observable<IHeaderstock[]> {
        let stockheaderdetail = stock;
        console.log(stockheaderdetail)
        let headers = new Headers({ 'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });
        return this._http.post('http://localhost:3031/api/Stockcountheader/' + 'Stock', stockheaderdetail, options)
            .map((response: Response) => <IHeaderstock[]>response.json())
            .catch(this.handleError);

    }
Posted
Comments
[no name] 27-Aug-19 10:58am    
Have you figured out what your want to do with this "out parameter" in your "angular 4 app"?

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