今天遇到一個有關ADO.NET 在更新資料時,
更新回資料庫的內容和實際輸入有差異的問題…
後來發現是DataSet的AcceptChange方法使用時機錯誤…

Dim dsChanges As DataSet = ds.GetChanges()
dsChanges.AcceptChanges() ---->正確的位罝
adDepMaster.Update(dsChanges, "department_master")
adDepDetail.Update(dsChanges, "department_detail")
dsChanges.AcceptChanges() ---->錯誤的位罝

我的想法,如果把資料Update回資料庫後再acceptChanges,因為dataset是屬於離線的資料庫,因此local的binding元件依然是以ds的資料為主。所以記得一定要先下AcceptChange方法,再Update回資料庫。
arrow
arrow
    全站熱搜

    湯瑪的吳 發表在 痞客邦 留言(0) 人氣()