我正在尝试下面这两个调用但是它们都返回一个异常Customer_ID不允许DBNull.Value.但是当我调试时,我看到我的所有记录都分配了Customer_ID.它是我的数据库表中唯一一个不可为空的定义.是什么导致了这个错误?
bulkCopy.WriteToServer(myBookingDataTable) bulkCopy.WriteToServer(myBookingss.ToArray())
这是我的整个代码.
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
确保源和目标中字段的顺序相同.
原文链接:https://www.f2er.com/vb/255321.html