C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ADO.NET »

SQL Bulk Copy


Posted Date: 22 Sep 2009    Resource Type: Code Snippets    Category: ADO.NET
Author: RanjithMember Level: Gold    
Rating: 1 out of 5Points: 3



This is used to store bulk data to DB.


private void SaveBulkData(DataTable Dt)
{
// Destination connection
SqlConnection destinationConn = new SqlConnection(DestinationconnString);
// Open connection.
destinationConn.Open();
// Create SqlBulkCopy Object
SqlBulkCopy bulkDataObj = new SqlBulkCopy(destinationConn);
// Set destination table name
bulkData.DestinationTableName = "Product";
// Write data to srerver
bulkDataObj.WriteToServer(Dt);
// Close objects
bulkDataObj.Close();
destinationConn.Close();
}



Responses

Author: harjit    01 Oct 2009Member Level: Bronze   Points : 2
SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder();
cb.DataSource = "SQLProduction";
cb.InitialCatalog = "Sales";
cb.IntegratedSecurity = true;
SqlConnection cnn = new SqlConnection(cb.ConnectionString);

// Getting source data
SqlCommand cmd = new SqlCommand("SELECT * FROM PendingOrders",cnn);
cnn.Open();
SqlDataReader rdr = cmd.ExecuteReader();

// Initializing an SqlBulkCopy object
SqlBulkCopy sbc = new SqlBulkCopy("server=.;database=ProductionTest;" + "Integrated Security=SSPI");

// Copying data to destination
sbc.DestinationTableName = "Temp";
sbc.WriteToServer(rdr);

// Closing connection and the others
sbc.Close();
rdr.Close();
cnn.Close();


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
SQL Bulk Copy  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Read Data From Excel sheet using Excel.Application Object
Previous Resource: Stored Procedure demo ADO.NET Example
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use