Is sqkbulkcopy a table schema replacement?

c# sqlbulkcopy


Using sqlbulkcopy, I was entering large amounts of data from C# code. 15000 records made up the temp upload table. Now somehow the datatable in WriteToServer() method had just one column and 37 rows.

I discovered that the table only had 37 entries after executing it. It had 152 columns at first, but after this, just 32 columns remained.

What may be the cause of this?

For this, use C#

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

I doubt that SqlBulkCopy modifies the schema since the sample code provided on this MSDN page contains scripts that build tables with the necessary information before carrying out the copy operation. Additionally, because mappings are not required to change the destination tables' structure, SQLBulkCopy uses column mappings, which is incorrect.

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