943,746 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2965
  • VB.NET RSS
Apr 28th, 2009
0

Difficulties with getchanges() method of datatable

Expand Post »
Hi all,

I'm facing some difficulties with the getchanges method of a datatable...

In my program, I have a standalone datatable which I'm using as the datasource to a datagridview. When I make changes to the datagridview, and I use the getchanges(DataRowState.Modified) method, I get Nothing as the result, no matter what changes I made. I also tried using the table as bindingsource to the datagridview but this didn't help either. Can anybody please point me out what I'm doing wrong? Below is my code:

- usr is an object that contains a table named table
- dgv is a datagridview on my form
- the update sub is a member of usr which is called when a button on the form is clicked
VB.NET Syntax (Toggle Plain Text)
  1. BindingSource1.DataSource = usr.table
  2. BindingSource1.RaiseListChangedEvents = True
  3. dgv.DataSource = BindingSource1
  4.  
  5. public sub update()
  6.  
  7. dim tmpdt as new datatable
  8. tmpdt = table.getchanges(DataRowState.Modified)
  9.  
  10. end sub

Thanks in advance.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TriceD is offline Offline
21 posts
since Dec 2008
Apr 28th, 2009
0

Re: Difficulties with getchanges() method of datatable

This example code explains maybe :=)

VB.NET Syntax (Toggle Plain Text)
  1. Dim _DT As DataTable = Nothing
  2.  
  3. Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  4. _DT = New DataTable
  5. _DT.BeginLoadData()
  6.  
  7. For i As Integer = 0 To 5
  8. Dim _Col As DataColumn = New DataColumn("", System.Type.GetType("System.String"))
  9. _DT.Columns.Add(_Col)
  10. _Col.Dispose()
  11. _Col = Nothing
  12. Next
  13.  
  14. For i As Integer = 0 To 5
  15. Dim _Row As DataRow = _DT.NewRow
  16. _Row.Item(0) = String.Format("Test {0}", i.ToString)
  17. _DT.Rows.Add(_Row)
  18. Next
  19. _DT.EndLoadData()
  20. _DT.AcceptChanges()
  21. Me.BindingSource1.DataSource = _DT
  22.  
  23. Me.DataGridView1.DataSource = Me.BindingSource1
  24.  
  25. End Sub
  26.  
  27. Private Sub BindingSource1_CurrentItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingSource1.CurrentItemChanged
  28. Dim tmpTable As DataTable = _DT.GetChanges(System.Data.DataRowState.Modified)
  29. Me.DataGridView2.DataSource = tmpTable
  30. End Sub

MSDN says....
Quote ...
When you call AcceptChanges on the DataSet, any DataRow objects still in edit-mode end their edits successfully. The RowState property of each DataRow also changes; Added and Modified rows become Unchanged, and Deleted rows are removed.
Reputation Points: 33
Solved Threads: 10
Junior Poster in Training
4advanced is offline Offline
67 posts
since Nov 2008
Apr 29th, 2009
0

Re: Difficulties with getchanges() method of datatable

Thanks 4advanced... with your help, I've managed to solve the problem... I had to call acceptchanges() after having set the datatable as binding source and subsequently the bindingsource as the datasource of the datagridview. Thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TriceD is offline Offline
21 posts
since Dec 2008
Apr 29th, 2009
0

Re: Difficulties with getchanges() method of datatable

double post
Last edited by TriceD; Apr 29th, 2009 at 10:39 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TriceD is offline Offline
21 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: how to add new row in datagridview on enter of any cell
Next Thread in VB.NET Forum Timeline: Problem with passing a variable





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC