Huge Bulk Copy insert Sql Code

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 774
Bulk Copy Customized Method Selected Field

public void CopyData()
{
string SourceconnStr = ConfigurationManager.ConnectionStrings["SourceConnectionString"].ToString();
string DesinatconnStr = ConfigurationManager.ConnectionStrings["DesiConnectionString"].ToString();

SqlConnection source = new SqlConnection(SourceconnStr);
SqlConnection destination = new SqlConnection(DesinatconnStr);
SqlCommand cmd = new SqlCommand("DELETE FROM Tempdetails", destination);


source.Open();
destination.Open();
cmd.ExecuteNonQuery();


cmd = new SqlCommand("Select USerName,Password from Login", source);
// Execute reader
SqlDataReader reader = cmd.ExecuteReader();
// Create SqlBulkCopy
SqlBulkCopy bulkData = new SqlBulkCopy(destination);
// Set destination table name
bulkData.DestinationTableName = "Tempdetails";
// Write data
bulkData.WriteToServer(reader);
// Close objects
bulkData.Close();
destination.Close();
source.Close();
}


refer this

http://www.c-sharpcorner.com/UploadFile/mahesh/BulckCopyAdoNet2008192005135138PM/BulckCopyAdoNet20.aspx

Comments or Responses

Login to post response