Answered by:
DataRow BeginEdit Without EndEdit

Question
-
I have DataTable and I view it in grid for read only, but in background (but on Main Thread) I watch the source data to track data change, when the source data change I change the Datatable, and tell the grid to refresh view in some how.
I want to make background refresh faster.
This is my code.
Private dtView As DataTable Public Sub RefreshRows(dtChangedRows As DataTable) Dim Cols = dtView.Columns For i = 0 To dtChangedRows.Rows.Count - 1 Dim SR = dtChangedRows(i) Dim ID As String = SR("Name").ToString Dim DR = dtView.Rows.Find(ID) For C = 0 To dtView.Columns.Count - 1 DR.BeginEdit() DR(Cols(C)) = SR(Cols(C).ColumnName) 'What Happend if i stop the next Line 'Is There affect? DR.EndEdit() 'Line 1 DR.AcceptChanges() 'Line 2 Next Next End Sub
My question is:
What Happens if i stop Line 1 And Line 2
Is there any bad effect of that?
Thanks for Any Help.
- Edited by Attaf Thursday, September 3, 2020 10:03 PM
Thursday, September 3, 2020 9:59 PM
Answers
-
Hi Attaf,
Did you solve your problem? If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.
Best Regards,
Xingyu ZhaoMSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- Marked as answer by Attaf Saturday, September 19, 2020 2:31 AM
Tuesday, September 15, 2020 7:11 AM
All replies
-
Hi Attaf,
We’re doing research on this issue. It might take some time before we get back to you.
Thank you for your understanding.
Best Regards,
Xingyu Zhao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Friday, September 4, 2020 9:53 AM -
Line 1, if you remove it, the push down from data will be done only if you change a row in the control. If you only close the form the push down will otherwise not done
Line 2, if you remove it, the editing makes sense. If you keep it all rows will be set to not changed and therefore done changes make no sense. It is meant to be used after an update of the database in situations where for instance only a subset of the data is updated.
Try to read the documentation instead of guessing what the programmer did mean for instance with "acceptchanges". This one is one of the most misunderstood methods.
Be aware, currently all your code is really culprit. The only thing it does is undo everything what is changed.
Success
Cor
- Edited by Cor Ligthert Friday, September 4, 2020 11:05 AM
Friday, September 4, 2020 10:59 AM -
Thank you for the answer
The question in short:
Is there a negative impact of leaving DataRow in (BeginEdit Mode) until the end of the program?Friday, September 4, 2020 2:10 PM -
I see now that the documentation on MSDN has become very unclear, likewise if the one who wrote it was also giving his own dream to the methods.
You have to know that a datarow has 2 sets of fields. One which you see and one those who are hidden (private). What happens in your code with acceptchanges is that the hidden fields (which are used when you update a database) are overwriting the standard fields. And then the rowstate is set to unchanged. More in general also the removed rows are deleted. Therefore the distinct with a datatable in deleted and removed. In the later is only the rowstate set to remove.
A dataadapter or its derived classes likewise TableAdapter does then see them as unchanged and does not update them.
The acceptchanges is good when you don't use a database but for instance writes the datarows to an XML file.
Success
Cor- Edited by Cor Ligthert Friday, September 4, 2020 5:20 PM
- Proposed as answer by KareninstructorMVP Monday, September 7, 2020 12:38 PM
Friday, September 4, 2020 5:19 PM -
Hi Attaf,
The Current and Proposed values become available when calling the DataRow object's BeginEdit method and by using EndEdit method, the Proposed value will become the Current value.
Besides, if you call "AcceptChanges", this will make all rows RowState "Unchanged", then DataAdapter's Update method cannot update your rows.Best Regards,
Xingyu Zhao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Monday, September 7, 2020 7:47 AM -
Hello,
Bottom line is by reading Microsoft's documentation there is really in this case to use EndEdit as AcceptChanges calls EndEdit.
Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
NuGet BaseConnectionLibrary for database connections.
Monday, September 7, 2020 12:38 PM -
Hi Attaf,
Did you solve your problem? If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.
Best Regards,
Xingyu ZhaoMSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- Marked as answer by Attaf Saturday, September 19, 2020 2:31 AM
Tuesday, September 15, 2020 7:11 AM