I have a data table .I want to push it to the sql table using Sqlbulkcopy .
- Data table dt=new datatable();some data were loaded
- Push this data to sql table.
- string connectionstring = @"Data Source";
- using (SqlConnection destinationConnection = new SqlConnection(connectionstring))
- {
- destinationConnection.Open();
- using (SqlBulkCopy bulkCopy =new SqlBulkCopy(destinationConnection.ConnectionString)) {
- bulkCopy.DestinationTableName = "studentmanagement";
- bulkCopy.ColumnMappings.Add("Name", "Name");
- bulkCopy.ColumnMappings.Add("Subjectname", "Subjectname");
- bulkCopy.ColumnMappings.Add("Marks", "Marks");
- bulkCopy.WriteToServer(dt);
- }
- destinationConnection.Close();
- }
Error populating Cannot access the destination table.
Its not working.please anyone help me to solve this?