Re-Sorting DataTables

M

MR

How can I re-sort a the rows in a data table?

Here is the example:
I read a data set that is sorted by probability. Then some algorithm
recalculates the probability field in each record.. As a result of the new
probability value, the rows very often are no longer sorted. to continue the
processing i need to have the rows sorted based on the new probability.
If i just do dataTable.DefaultView.Sort = "[Probability]", the rows are not
sorted.
however if i create a view based on the default view, and set the sort (or
visa versa), the rows are sorted but then i can't use the view to update the
database (even if i create a datatable form this view). i get an error that
says that something like i need to supply an insert statement in the update.
it must see the records in the dataview as new rows and not as modified row.
the only way i am able to have a data table that is correctly sorted is to
do an update with the changes and then re-query to create a new datatable.
there has got to be a better way to do this.

does anyone have any ideas?
m
 
K

Kevin Yu [MSFT]

Hi MR,

I agree with Scott that the rows in a DataTable needn't to be sorted
physically. Like the tables in database, the DataTable is just a container
to store data. When you need them in certain order, use DataView to sort
them logically.

Here is another man who's trying to do the same like yours. You can check
this for more information

http://groups.google.com/group/microsoft.public.dotnet.framework.adonet/brow
se_thread/thread/5bd69359108c76fc/72902b10c82c99c4?lnk=st&q=&rnum=1#72902b10
c82c99c4

If anything is unclear, please feel free to let me know.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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