c# - Linq to sql update does now work -
i'm trying update data database using linq. of other codes write in following method work expected update code @ marked line not work. no changes in database. have debugged , i'am getting values expected user. problem change expect in database. can problem ?
private void addtocart() { fixbaydbdatacontext db = new fixbaydbdatacontext(); if (session["customerauthentication"] != null) { carttbl carttbl = new carttbl(); cartshoetbl cstbl = new cartshoetbl(); int cusid = convert.toint32(session["customerauthentication"]); int shoeid = convert.toint32(sizeddl.text); var idquery = c in db.carttbls.asqueryable() c.customerid == cusid select new{c.cartid,c.customerid}; var shoequery = s in db.shoetbls.asqueryable() join m in db.shoemodeltbls on s.modelid equals m.modelid s.shoeid == shoeid select new { s.shoeid, m.price }; int quantity = convert.toint32(quantityddl.text); double shoeprice = (double)shoequery.first().price; double totalprice = quantity * shoeprice; //int shoeid = (int)shoequery.first().shoeid; //int lastshoeid = 0; if (idquery.any()) { int cartid = (int)idquery.firstordefault().cartid; var cartshoequery = ca in db.cartshoetbls.asqueryable() ca.cartid == cartid && ca.shoeid == shoeid select ca; if (cartshoequery.any()) { cstbl.quantity += convert.toint32(quantityddl.text); db.submitchanges(); } else { var cartquery = ca in db.carttbls.asqueryable() ca.customerid == cusid select new { ca.cartid, ca.totalprice }; double currenttotal = (double)cartquery.firstordefault().totalprice; currenttotal = currenttotal + totalprice; carttbl.totalprice = currenttotal; //update line db.submitchanges(); cstbl.cartid = cartquery.first().cartid; cstbl.shoeid = shoeid; cstbl.quantity = convert.toint32(quantityddl.text); db.cartshoetbls.insertonsubmit(cstbl); db.submitchanges(); } } else { carttbl.customerid = cusid; carttbl.totalprice = totalprice; db.carttbls.insertonsubmit(carttbl); cstbl.cartid = carttbl.cartid; cstbl.shoeid = shoeid; cstbl.quantity = quantity; db.cartshoetbls.insertonsubmit(cstbl); db.submitchanges(); } } else { response.write("<script>alert('please login before start shopping !');</script>"); } }
carttbl
never set value belongs database. it's new
carttbl created , it's not in database. need change that's in database update database.
Comments
Post a Comment