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?
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
Make sure the order of the fields in source and target are identical.