I have two data table .
I want to copy first 10 records of my first datatable to another datatable ... columns are coming dynamic so we cant mention the column name.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SUNIL GUTTAPosted Jan 13, 2014, 1:22 PM
datatable dt =new datatable();
dt ----- > fill this
VulpesPosted Jan 13, 2014, 9:29 AM
The DataTable.Copy method copies all the rows but doesn't have an overload which copies only a subset of them. If you were copying nearly all the rows, then it might be quicker to copy all of them and then remove the ones you don't want.
Do you really need to copy the rows at all? Couldn't you just operate from the original DataTable?
santosh paridaPosted Jan 13, 2014, 12:01 AM
VulpesPosted Jan 11, 2014, 8:56 AM
To copy the top 50 records, change this line:
santosh paridaPosted Jan 11, 2014, 7:37 AM
But unfortunately i have a large database. so i can't use for loop.
For example Can we copy top 50 records to another datatable from first datatable.
Sanjay KumarPosted Jan 11, 2014, 7:32 AM
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q308909
http://stackoverflow.com/questions/4020270/copy-rows-from-datatable-to-another-datatable-c-sharp
VulpesPosted Jan 11, 2014, 6:26 AM
Sunny SharmaPosted Jan 11, 2014, 6:10 AM
In relational Database, there's no concept for inserting the values without column name unless you have all the values matching to al the column in an order. You have to have the names.
Although it's coming dynamically, you need to get the column name from what it's coming and the insert the columns accordingly.
Share your code what you've tried so far or where you're stuck?