Is sqkbulkcopy a table schema replacement?

c# sqlbulkcopy


I was inserting bulk data from C# code using sqlbulkcopy.There were 15000 records in temp_upload table.Now somehow the datatable in WriteToServer() method had just one column and 37 rows.

After running it I found that the table just had 37 records.Initially it had 152 columns but after this only 32 columns were left.

What could be the reason for this?

C# code for this

public static void BulkInsert(SqlConnection connection,DataTable DtRecord,string   TableName)

        if (DtRecord == null) throw new ArgumentNullException("dataTable");
        // Create & open a SqlConnection, and dispose of it after we are done

            SqlBulkCopy bulkCopy = new SqlBulkCopy(connection);
            bulkCopy.DestinationTableName = TableName;
            for (int recordLoop = 0; recordLoop < DtRecord.Columns.Count; recordLoop++)
                bulkCopy.ColumnMappings.Add(DtRecord.Columns[recordLoop].ColumnName, DtRecord.Columns[recordLoop].ColumnName);


9/30/2009 4:22:49 PM

Popular Answer

The example code given at this MSDN page has scripts that create tables with the appropriate fields prior to performing the copy operation, so I doubt that SqlBulkCopy changes the schema. Further, SQLBulkCopy utilizes column mappings, which would be inconsistent with changing the schema of the target tables, since mappings would not be needed to do that.

9/30/2009 3:45:38 PM

Related Questions

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow