Editing data within a datatable

A

AC

I have a datatable that contains data I'm inserting programatically (not from a datasource... using between postbacks to persist data). I need to be able to update the elements within the table, but I also need to sort the elements using a DataView. Here's my code as it stands:
Dim dv As DataView = New DataView(Me._selectedQuickLinks, String.Empty, "SortOrder ASC", DataViewRowState.CurrentRows)
dv.AllowEdit = True
' step through all rows and update the sort order to whole numbers
For Each row As DataRowView In dv
row.BeginEdit()
row("SortOrder") = i
row.EndEdit()
i += 1
Next
Me._selectedQuickLinks.AcceptChanges()


However my table isn't getting the updated values... (by default they started with 999, and when I write it out, they are always 999).
 
M

Miha Markic

Hi,


I can't recreate your problem. It works just fine for me.
One thing that may cause problems is that you are first sorting view based
on SortOrder and then you are changing it within foreach loop.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rhand.com

I have a datatable that contains data I'm inserting programatically (not
from a datasource... using between postbacks to persist data). I need to be
able to update the elements within the table, but I also need to sort the
elements using a DataView. Here's my code as it stands:
Dim dv As DataView = New DataView(Me._selectedQuickLinks, String.Empty,
"SortOrder ASC", DataViewRowState.CurrentRows)
dv.AllowEdit = True
' step through all rows and update the sort order to whole numbers
For Each row As DataRowView In dv
row.BeginEdit()
row("SortOrder") = i
row.EndEdit()
i += 1
Next
Me._selectedQuickLinks.AcceptChanges()

However my table isn't getting the updated values... (by default they
started with 999, and when I write it out, they are always 999).
 
K

Kathleen Dollard

In this sentence, does "table" refer to the ADO.NET DataTable, or the backend database table?

If the second, remove AcceptChanges and see if it works.
However my table isn't getting the updated values... (by default they started with 999, and when I write it out, they are always 999).


--
Kathleen Dollard
Microsoft MVP
Author "Code Generation in Microsoft .NET"


I have a datatable that contains data I'm inserting programatically (not from a datasource... using between postbacks to persist data). I need to be able to update the elements within the table, but I also need to sort the elements using a DataView. Here's my code as it stands:
Dim dv As DataView = New DataView(Me._selectedQuickLinks, String.Empty, "SortOrder ASC", DataViewRowState.CurrentRows)
dv.AllowEdit = True
' step through all rows and update the sort order to whole numbers
For Each row As DataRowView In dv
row.BeginEdit()
row("SortOrder") = i
row.EndEdit()
i += 1
Next
Me._selectedQuickLinks.AcceptChanges()


However my table isn't getting the updated values... (by default they started with 999, and when I write it out, they are always 999).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top