Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to excel copy to database table.But this line is error.

bulkCopy.WriteToServer(dt);


And error is DestinationTableName :
The DestinationTableName property must be set before calling this method.

I want copy this table:

MY DATABASE NAME:READTEST
TABLE NAME:Students

What I have tried:

public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }
Posted
Updated 9-Jun-19 17:57pm
v2
Comments
[no name] 8-Jun-19 2:28am    
copy.DestinationTableName = symbolName;
[no name] 8-Jun-19 4:52am    
Thank you so much.I write bulkCopy.DestinationTableName = "Students"; and done
ZurdoDev 10-Jun-19 16:35pm    
Please post as solution.
Richard MacCutchan 8-Jun-19 4:05am    
Do what the message tells you and set the DestinationTableName to a valid table name.
#realJSOP 11-Jun-19 9:42am    
I wonder why the SqlBulkCopy object doesn't automagically use the table name specified in the DataTable object... I recently implemented a generic BulkInsert method and tripped over the same problem. I just assumed that the SqlBulkCopy object would do what's right.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900