Difficulties with getchanges() method of datatable

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2008
Posts: 18
Reputation: TriceD is an unknown quantity at this point 
Solved Threads: 0
TriceD TriceD is offline Offline
Newbie Poster

Difficulties with getchanges() method of datatable

 
0
  #1
Apr 28th, 2009
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
  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: Difficulties with getchanges() method of datatable

 
0
  #2
Apr 28th, 2009
This example code explains maybe :=)

  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....
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 18
Reputation: TriceD is an unknown quantity at this point 
Solved Threads: 0
TriceD TriceD is offline Offline
Newbie Poster

Re: Difficulties with getchanges() method of datatable

 
0
  #3
Apr 29th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 18
Reputation: TriceD is an unknown quantity at this point 
Solved Threads: 0
TriceD TriceD is offline Offline
Newbie Poster

Re: Difficulties with getchanges() method of datatable

 
0
  #4
Apr 29th, 2009
double post
Last edited by TriceD; Apr 29th, 2009 at 10:39 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC