Returning n number of rows in datatable format from datatable object
-
lunes, 16 de abril de 2012 10:04I am using following code to return n number of rows from DataTable to another DataTable object. It is working fine when in first datatable records comes from database but when I mannualy added records in datatable then it crash and a message displays no rows.
I had debugeed and found that currentTable.DefaultView.ToTable().Rows.Cast<DataRow>() this will returns null value.
I had written following code to select n records from DataTable object
currentTable = currentTable.DefaultView.ToTable().Rows.Cast<DataRow>().Take(numberOfRecord).CopyToDataTable();
I dont know why it is crashed when I manualy creating DataTable and working fine when records comes from DataReader to DataTable.
Todas las respuestas
-
lunes, 16 de abril de 2012 10:36
Below is an answer to similar question. Check it out,
I hope this helps.
Please mark this post as answer if it solved your problem. Happy Programming!
- Marcado como respuesta Bob ShenMicrosoft Contingent Staff, Moderator martes, 01 de mayo de 2012 3:35
-
lunes, 16 de abril de 2012 12:33
Hi,
And
When you say crashed, which part it is causing problem? Is exception is InvalidOperationException? If so this is because call to CopyToDataTable() on no row result.
Hope this helps you..
If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
- Marcado como respuesta Bob ShenMicrosoft Contingent Staff, Moderator martes, 01 de mayo de 2012 3:35
-
lunes, 16 de abril de 2012 17:06
Can you please provide more detail.
If sample code is provided then it would be better.

