sqlbulkcopy - does not allow DBNull.Value.?

sqlbulkcopy vb.net

Question

I am trying these 2 calls below but both of them returns me an exception Customer_ID does not allow DBNull.Value. but when I debug, I see that all my records have Customer_ID assigned. It is the only one as not nullable defined on my DB table. what is causing that error?

   bulkCopy.WriteToServer(myBookingDataTable)

   bulkCopy.WriteToServer(myBookingss.ToArray())

here is my entire code.

    Using myConnection As SqlConnection = _
                New SqlConnection(connectionString)
                myConnection.Open()


                Using bulkCopy As SqlBulkCopy = _
                  New SqlBulkCopy(My.Settings.ConnectionString(), SqlBulkCopyOptions.Default)

                    bulkCopy.DestinationTableName = "dbo.Booking"

                    Try
                        ' Write from the source to the destination.
                         bulkCopy.WriteToServer(myBookingDataTable)

                        'bulkCopy.WriteToServer(myBookingss.ToArray())

                    Catch ex As Exception
                        Console.WriteLine(ex.Message)

                    Finally

                        bulkCopy.Close()
                    End Try
                End Using
1
8
8/31/2012 4:14:17 PM

Accepted Answer

Make sure the order of the fields in source and target are identical.

15
9/4/2012 2:48:00 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