Dim conn As SqlConnection = GetConnection()
'不先open連線會造成BeginTransaction發出錯誤訊息
conn.Open()
Dim tran As SqlTransaction = conn.BeginTransaction
Try
Using bcp As SqlBulkCopy = New SqlBulkCopy(conn, SqlBulkCopyOptions.Default, tran)
'對應的Table和欄位,如果兩張Table一模一樣欄位可以不用Mapping
bcp.DestinationTableName = tableName
bcp.ColumnMappings.Add("欄位")
' 填入要上傳的Table
bcp.WriteToServer(UploadTable)
Catch ex As Exception
MsgBox(ex.Message)
End Try
沒有留言:
張貼留言