Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
3.75/5 (4 votes)
See more:
Hi to all
How to shuffle datatable rows in C#?
Thanks
Posted
Comments
#realJSOP 27-Dec-10 8:29am    
Ummm... why?
javadi_84 27-Dec-10 8:43am    
I am using these data as input parameter of an algorithm and I want to run algorithm by same data but with different order

One way to do this shown here[^].
 
Share this answer
 
Comments
Dalek Dave 27-Dec-10 18:26pm    
Yes, but why do it?
Abhinav S 27-Dec-10 23:47pm    
Good question - DD.
Pick them in random order or randomize it after picking! Why to shuffle row in DB?
 
Share this answer
 
What possible need do you have for random shuffling of the datatable rows?

The order is immaterial, so long as the data is there it can be pulled by the query.

The datatable is invisible to the user, and it is not important what order it is in.

Can you explain the reason you wish to do this?
 
Share this answer
 
Increase a field in datatable with name say ShuffleID


make use of random number without repeater algorithm

suppose there is 100 rows in table

random algorithm might give you number like 10, 4, 99, 67
store this number to ShuffleID field

sort datatable by ShuffleID
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900