Click here to Skip to main content
15,936,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
say i have 10000 records in one table i just want 100 record from this datable A to Datatable B , is there any easy way other than loop ?
Posted
Comments
Kumarbs 1-Aug-14 2:15am    
Which db you are using? And you are asking 100 records, meant based on some condition or top 100?
Improve your question.
Thanks7872 1-Aug-14 2:32am    
He is talking about datatable. This question has nothing to do with db.
Kannannns 1-Aug-14 2:55am    
using framework 2.0, its like navigating through records, 100 records first, then next 100....so on

Try lambda expression:
C#
Datatable1.AsEnumerable().Where(s=>s.Field<stirng>("SomeColumn") == "SomeValue").CopyToDataTable(Datatable2, LoadOption.Upsert);
//Here Datatable1 is having 1000 records(assume), and you are copying the datatable to Datatable2
</stirng>



[Update]
Then how about this?
C#
DataRow[] dr = DataTable1.Select("ColumnName='columnvalue'");

and then:
C#
foreach (DataRow row in dr ) {
   DataTable2.ImportRow(row);
}

--Amy
 
Share this answer
 
v2
Comments
_Amy 1-Aug-14 2:55am    
See my updated solution..
Kannannns 1-Aug-14 2:58am    
dont want to use loop
_Amy 1-Aug-14 3:01am    
A loop is required to add the rows in DataTable in Net Framework 2.0.
Hello ,
If you are using LINQ ,then another solution ...
<br />
table1.AsEnumerable().Take(noofcount).CopyToDataTable(table2,LoadOption.OverwriteChanges);<br />


thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900