問題
使用 Entities 更新資料
解決方法
更新資料到Entities之前,要先將資料取出,藉由變更取出的資料,將之變更回資料庫
using (Entities db = new Entities())
{
using (TransactionScope tran = new TransactionScope())
{
DateTime dt = DateTime.Now;
string odGuid = form["guid"];
var custOpenDeptRow =
(from custOpenDept in db.CustOpenDept
where custOpenDept.CUSTOPENDEPT_GD == "PKey"
select custOpenDept).First();
custOpenDeptRow.LAST_CHNG_DT = dt;
db.SaveChanges();
tran.Complete();
db.AcceptAllChanges();
}
}
沒有留言:
張貼留言