question

Andy 2 avatar image
Andy 2 asked

SQL Server 2005 SqlBulkCopy

Hello, my table structure has 6 columns, with a primary key on all six columns. When I use the SQLBulkCopy.WriteToServer(DataReader) it's trying to insert a row that does not exist. The source data is stored in an Excel spread sheet. A windows forms app. is used to update the database from the excel data.

sql-server-2005excel
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
RickD avatar image
RickD answered

You have anomalous rows in Excel.

If you run (in T-SQL):

select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',             
'Excel 8.0;Database=<your file including location.xls>',             
'SELECT * FROM [<your workbook>]')            

There should be rows that are null and you wouldn't want imported.

You can add a where clause to the above to get rid of them.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.