c# - LINQ to SQL stored procedures issue -
i trying learn more web development c# , asp.net.
i using linq store values contact form in database, however, database requires 'policy id' generated calling stored procedure.
i have absolutely no idea how calling stored procedure, obtaining integer value generated , using value set policyid in table.
could provide me process work so:
execute sproc, return policy id. policyid, set policyno. add policyno db.policyid
i appreciate of information may appear quite amateurish, have never used linq nor stored procedures before. have been front end developer until now.
thanks in advance!
edit:
here c# code used far:
using (magtestdatacontext context = new magtestdatacontext()) { //create new instance of tblpolicy object tblpolicy policy = new tblpolicy(); var policyno = context.spnextpolicyid(); //add values field policy.policyid = policyno; policy.policyholder = tbname.text; policy.email = tbemail.text; policy.telephone = tbtelephone.text; policy.address1 = tbaddressline1.text; policy.address2 = tbaddressline2.text; policy.address3 = tbaddressline3.text; policy.address4 = tbaddressline4.text; policy.postcode = tbpostcode.text; policy.extrainfo10 = tbinsurer.text; policy.extrainfo11 = ddreason.text; policy.extrainfo12 = tbother.text; }
it looks you're using entity framework. if so, can execute stored procedure using:
using (magtestdatacontext context = new magtestdatacontext()) { var policyid = db.executequery<int>("declare @ret int; exec spnextpolicyid @ret output; select @ret").single(); }
Comments
Post a Comment