asp.net mvc 4 - Having error in updating my record in database my method as follows -
what have done wrong in code ? (i using mvc4 , ef) example: please clear fresher use mvc4
editresponse response = new editresponse(); try { using (wematchcontext db = new wematchcontext()) { b_member_register update = new b_member_register(); var output = db.b_member_register.where(x => x.member_id == model.member_id).firstordefault(); if(output != null ) { update.first_name = model.first_name; update.last_name = model.last_name; update.gender = model.gender; update.dob = model.dob; int resultcount = db.savechanges(); if (resultcount > 0) { response.member_id = update.member_id; response.resultcode = 0; response.message = "updated successfully"; }
you have attach updated data db entity. please try this,
using (wematchcontext db = new wematchcontext()) { var update = db.b_member_register.where(x => x.member_id == model.member_id).firstordefault(); if(update != null ) { update.first_name = model.first_name; update.last_name = model.last_name; update.gender = model.gender; update.dob = model.dob; //below line of code important. db.b_member_register.attach(update); db.entry(update).state = entitystate.modified; int resultcount = db.savechanges(); if (resultcount > 0) { response.member_id = update.member_id; response.resultcode = 0; response.message = "updated successfully"; } } }
Comments
Post a Comment