Returning n number of rows in datatable format from datatable object
-
16 aprilie 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.
Toate mesajele
-
16 aprilie 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!
- Marcat ca răspuns de Bob ShenMicrosoft Contingent Staff, Moderator 1 mai 2012 03:35
-
16 aprilie 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".
- Marcat ca răspuns de Bob ShenMicrosoft Contingent Staff, Moderator 1 mai 2012 03:35
-
16 aprilie 2012 17:06
Can you please provide more detail.
If sample code is provided then it would be better.