-1

I'm trying to shuffle DataTable rows by a specific column (campaign_id) in this example. I tried what's suggested in this question cannot shuffle rows of DataTable

but I need to be more specific as I mentioned,

Here is an example: this is the DataTable I have, it is sorted by campaign_id column

soruce

and I want the result to be (shuffling campaign_id) like this:

result

B.Simboliq
  • 55
  • 7

1 Answers1

1
var rnd = new Random();
var shuffled = dataTable.Rows.Cast<DataRow>().OrderBy(r => rnd.Next()).CopyToDataTable();
Alexander Petrov
  • 13,457
  • 2
  • 20
  • 49