Bulk Copy from Dot Net to SQL Table

Puneet20884
Posted by Puneet20884 under ASP.NET category on | Views : 2464
Hi,
Its a simple self explaining block of C# code and goes as :

private void BulkDataCopy(DataTable Dt)
{

SqlConnection dConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());

SqlBulkCopy dataObj = new SqlBulkCopy(dConn);
try
{
dConn.Open();
dataObj.DestinationTableName = "as_tblMembersCountries";
// Write data to srerver
dataObj.WriteToServer(Dt);
objErrorLog.WriteLog("Bulk Save Successful","","");
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.Message, ex.StackTrace, "");
objErrorLog.WriteLog("Bulk Save Failed", "", "");
}
finally
{
// Close objects
dataObj.Close();
dConn.Close();
}
}


Please feel free to ask any query or any doubt !!

Comments or Responses

Login to post response