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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sunny SharmaRank #223 · 11.1K reputationPosted Jan 11, 2014, 1:10 AM EST
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?
VulpesRank #55 · 29.2K reputationPosted Jan 11, 2014, 1:26 AM EST
Sanjay KumarRank #561 · 4.3K reputationPosted Jan 11, 2014, 2:32 AM EST
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
santosh parida34 reputationPosted Jan 11, 2014, 2:37 AM EST
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.
VulpesRank #55 · 29.2K reputationPosted Jan 11, 2014, 3:56 AM EST
To copy the top 50 records, change this line:
santosh parida34 reputationPosted Jan 12, 2014, 7:01 PM EST
VulpesRank #55 · 29.2K reputationPosted Jan 13, 2014, 4:29 AM EST
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?
SUNIL GUTTARank #1,832 · 810 reputationPosted Jan 13, 2014, 8:22 AM EST
datatable dt =new datatable();
dt ----- > fill this