• On Life and Love

    SqlBulkCopy Matching Columns

    If you’re trying to do a SqlBulkCopy using a DataTable and getting lots of column type (integer, string) mismatches, it’s probably because you haven’t mapped not only the column types, but also the column names. SqlBulkCopy assumes that your DataTable is going to have its columns in the same order as the database table, which will cause mismatches when it tries to send your (string) Name field into your (int) Age column. Just having your DataTable column names match the table isn’t enough, either. There must be a manual mapping. But if your DataTable column names are the same as the table column names, a simple method can take care…