I utilse TableAdapters throughout my entire application, because I prefer working with strongly typed Datasets. I have come up with a small problem, though: Whenever I attempt to Update a particular DataRow with the methods shown in the Title, no updates
are actually made to that row. Here is my code:
Public Function UpdateMemAccount(AccNo As Integer, MemID As Integer, Value As Double) As Boolean
' Return true if update was successfull
Dim accAdap As New ClubsTableAdapters.tblACCOUNTSTableAdapter
Dim accounts As Clubs.tblACCOUNTSDataTable
Dim account As Clubs.tblACCOUNTSRow
Dim OldOutstanding As Double
Dim NewOutstanding As Double
accounts = accAdap.GetThisMemberAccount(MemID)
If accounts.Count <> 0 Then
account = accounts.FindByACCOUNT_NO(AccNo)
OldOutstanding = account.OUTSTANDING
NewOutstanding = OldOutstanding + Value
account.BeginEdit()
account.OUTSTANDING = NewOutstanding
account.AcceptChanges()
Return True
Else
Return False
End If
End Function
The statement I've referred above should be removed. Because once you've imported all the data contents into a memory-based DataTable, Each DataRow will modify the RowState from "Unchanged" to "Modified", And when you call Update method from a DataAdapter(whether
it's strongly-typed or not), it will check RowState one by one and do inserting or updating. But if you call "AcceptChanges", this will make all the rows return to "Unchanged". So that's the reason you cannot update your rows, even if data contents have all
been changed.
Member
42 Points
197 Posts
How do I use the BeginEdit() and EndEdit()/AcceptChanges() methods for a DataRow?
Aug 30, 2011 09:08 AM|Deyken|LINK
Hi All,
I utilse TableAdapters throughout my entire application, because I prefer working with strongly typed Datasets. I have come up with a small problem, though: Whenever I attempt to Update a particular DataRow with the methods shown in the Title, no updates are actually made to that row. Here is my code:
What am I doing wrong?
Deyken
DeezineTech South Africa
All-Star
94120 Points
18123 Posts
Re: How do I use the BeginEdit() and EndEdit()/AcceptChanges() methods for a DataRow?
Aug 31, 2011 10:30 PM|Decker Dong - MSFT|LINK
Hello,
The statement I've referred above should be removed. Because once you've imported all the data contents into a memory-based DataTable, Each DataRow will modify the RowState from "Unchanged" to "Modified", And when you call Update method from a DataAdapter(whether it's strongly-typed or not), it will check RowState one by one and do inserting or updating. But if you call "AcceptChanges", this will make all the rows return to "Unchanged". So that's the reason you cannot update your rows, even if data contents have all been changed.
Thx again