c# - Updating through LINQ in different DataBase -
i have db looks this:
1st:
commissionsv2 (table = entity_product_point)
dbml has 1 table.
2nd:
webenroll (table = planmaster)
dbml has 1 table in it.
now through linq adding row in has query this:
commissionsv2datacontext cv = new commissionsv2datacontext(); entity_product_point ev = new entity_product_point(); ev.entity_id = getentity; ev.product_id = tr.first(); ev.hicommissionold = (double)firststyrcomp; ev.lowcommissionold = (double)recurringcomp; ev.hicommission = (double)finalfirstyrcomp * 100; ev.lowcommission = (double)finalrecurringcomp * 100; ev.datecreated = system.datetime.now; cv.entity_product_points.insertonsubmit(ev); cv.submitchanges(); now update statement this:
protected void gvshowcomm_rowupdating(object sender, gridviewupdateeventargs e) { //getting entity_id session! int getentity = int16.parse(session["entityselected"].tostring()); //accessing variables controls! system.web.ui.webcontrols.textbox product_id = gvshowcomm.rows[e.rowindex].findcontrol("productname") system.web.ui.webcontrols.textbox; system.web.ui.webcontrols.textbox planname = gvshowcomm.rows[e.rowindex].findcontrol("planname") system.web.ui.webcontrols.textbox; system.web.ui.webcontrols.textbox hicommold = gvshowcomm.rows[e.rowindex].findcontrol("hicomm") system.web.ui.webcontrols.textbox; system.web.ui.webcontrols.textbox lowcommold = gvshowcomm.rows[e.rowindex].findcontrol("lowcomm") system.web.ui.webcontrols.textbox; //storing values variables! int product = int16.parse(product_id.text); string plan = planname.text; int hiold = int16.parse(hicommold.text); int lowold = int16.parse(lowcommold.text); //updating values table through linq! dbwebenrolldatacontext dt = new dbwebenrolldatacontext(); //this has planname in planmaster table. commissionsv2datacontext cv = new commissionsv2datacontext(); //entity_product_point has other columns needs updated! entity_product_point ev = cv.entity_product_points.single(c => c.product_id == product); ev.hicommissionold = hiold; ev.lowcommissionold = lowold; ev.entity_id = getentity; cv.submitchanges();
in order update, need retrieve entity needs updated.
so in case be:
entity_product_point ev = cv.entity_product_points.single(c => c.product_id == product); ev.hicommissionold = hiold; ev.lowcommissionold = lowold; // retrieve plan needs updated , set name // submit changes cv.submitchanges(); // retrieve new values , rebind gridview against new values
Comments
Post a Comment