Click here to Skip to main content
15,888,046 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi There,

I am working on windows service. I am developing an windows service which fetch record from flat file into datatable. Now this datatable records around 5 lacs rows want to insert in sql server. Please tell me the efficient way to do this task.
Posted

Use the SqlBulkCopy[^] class.
 
Share this answer
 
Comments
Maciej Los 23-Jul-14 4:54am    
Paul, you are really fast!
+5!
Hi,
For inserting large data into sql server better to use sql bulk copy like as follows

C#
DataTable mydatatable= mydata;
 // Get a reference to a single row in the table.
 DataRow[] rowArrayMydata = mydatatable.Select();

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con,    SqlBulkCopyOptions.KeepIdentity, transaction))
{

bulkCopy.DestinationTableName = "MyDestinationTable";
 // Write the array of rows to the destination.
 bulkCopy.WriteToServer(rowArrayMydata );

 }
 
Share this answer
 
v2

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