vb.net – sqlbulkcopy – 不允许DBNull.Value.?

前端之家收集整理的这篇文章主要介绍了vb.net – sqlbulkcopy – 不允许DBNull.Value.?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试下面这两个调用但是它们都返回一个异常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

猜你在找的VB相关文章