Dinesh Santhalingam

Dinesh Santhalingam

  • NA
  • 737
  • 358.8k

Bulk copy in Sql using C#

Jan 30 2017 1:16 AM
I have a data table .I want to push it to the sql table using Sqlbulkcopy . 
  1. Data table dt=new datatable();some data were loaded
  2. Push this data to sql table.
  3. string connectionstring = @"Data Source";  
  4.  using (SqlConnection destinationConnection = new SqlConnection(connectionstring))  
  5.   {  
  6.  destinationConnection.Open();  
  7.  using (SqlBulkCopy bulkCopy =new SqlBulkCopy(destinationConnection.ConnectionString))       {  
  8.       bulkCopy.DestinationTableName = "studentmanagement";  
  9.       bulkCopy.ColumnMappings.Add("Name", "Name");  
  10.       bulkCopy.ColumnMappings.Add("Subjectname", "Subjectname");  
  11.       bulkCopy.ColumnMappings.Add("Marks", "Marks");  
  12.       bulkCopy.WriteToServer(dt);  
  13.    }  
  14.    destinationConnection.Close();  
  15.  }  
 Error populating Cannot access the destination table.
Its not working.please anyone help me to solve this? 

Answers (9)