A type conversion error occurred in SQL BULK INSERT

Source: Internet
Author: User
Tags bulk insert

1. Reason: When using sqlbulkcopy batch operation, the map map will show the table node corresponding error.

2. Solution: Set up the field map yourself first

using (SqlConnection con = new SqlConnection (dbconfig.csnisconnstring))
{
Con. Open ();
using (sqltransaction Tran = con. BeginTransaction ())
{
SqlBulkCopy BC = new SqlBulkCopy (Con,
sqlbulkcopyoptions.checkconstraints |
Sqlbulkcopyoptions.firetriggers |
Sqlbulkcopyoptions.keepnulls, Tran);

Sqlbulkcopycolumnmapping m1 = new Sqlbulkcopycolumnmapping ("SchoolID", "SchoolID");
sqlbulkcopycolumnmapping m2 = new Sqlbulkcopycolumnmapping ("AreaCode", "AreaCode");
sqlbulkcopycolumnmapping m3 = new Sqlbulkcopycolumnmapping ("Lastpushdate", "lastpushdate");
Sqlbulkcopycolumnmapping m4 = new Sqlbulkcopycolumnmapping ("Studentcode", "Studentcode");
Sqlbulkcopycolumnmapping m5 = new Sqlbulkcopycolumnmapping ("Studentname", "studentname");
Sqlbulkcopycolumnmapping M6 = new Sqlbulkcopycolumnmapping ("Classcode", "Classcode");
Sqlbulkcopycolumnmapping m7 = new Sqlbulkcopycolumnmapping ("ClassName", "ClassName");
sqlbulkcopycolumnmapping m8 = new Sqlbulkcopycolumnmapping ("Managecode", "Managecode");
Sqlbulkcopycolumnmapping m9 = new Sqlbulkcopycolumnmapping ("Unpushcount", "Unpushcount");

Bc. Columnmappings.add (M1);
Bc. Columnmappings.add (m2);
Bc. Columnmappings.add (m3);
Bc. Columnmappings.add (M4);
Bc. Columnmappings.add (M5);
Bc. Columnmappings.add (M6);
Bc. Columnmappings.add (M7);
Bc. Columnmappings.add (M8);
Bc. Columnmappings.add (M9);

Bc. BatchSize = 10000;
Bc. DestinationTableName = "Xcard_pclexception"; Target table
Bc. WriteToServer (Listall.asdatareader ());
Tran.commit ();
}
Con. Close ();
}

A type conversion error occurred in SQL BULK INSERT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.