c# - I want to Split Datatable rows based on number -


I have a data format and I want to divide the number of rows by the foreach 12 line, for example if the rows The number is 61: This means 61/12 = 6 tables have 5 tables with 12 rows and 3 rows in Table number 6 C # Thank you very much

You can use the following LINQ query:

  DataTable [] splittedtables = tbl.AsEnumerable (). Select ((line, index) = & gt; new {line, index}). GroupB (x => x.index / 12) // integer division, partial part has been reduced. Select (G = & gt; G Select (x = & gt; x.row) .CopyToDataTable ()) .ToArray ();  

There are 6 tables in the array, 5 have 12 rows, the last line is in the last.

Checked with this sample-data:

  datatelle tbl = new datatelle (); Tbl.Columns.Add ("Columns"); For (Int I = 0; i & lt; 61; i ++) TBL Ro Add (i.ToString ());  

You will find the system .


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -