''' <summary> ''' テーブルデータの削除 ''' </summary> ''' <param name="tableName"></param> ''' <returns></returns> Private Async Function DeleteTable(ByVal tableName As String) As Task Try Using con As New SqlConnection(strConnection) Using cmd As New SqlCommand() Await con.OpenAsync() cmd.Connection = con cmd.CommandText = "DELETE FROM " & tableName cmd.CommandTimeout = 3600 Await cmd.ExecuteNonQueryAsync() con.Close() End Using End Using Catch ex As Exception MessageBox.Show(ex.Message) End Try End Function ''' <summary> ''' BulkCopyを利用したテーブル更新。 ''' </summary> ''' <param name="tableName">テーブル名</param> ''' <param name="dt">データテーブル</param> ''' <returns></returns> Private Async Function UpdateTableAsync(ByVal tableName As String, ByVal dt As DataTable) As Task '対象のテーブルを一括削除。 Dim Task1 = DeleteTable(tableName) '対象のテーブルにBulkCopy。 Dim Task2 = Task.Run(Sub() Try Using con As New SqlConnection(strConnection) Using sqlBulkCopy As New SqlBulkCopy(con) sqlBulkCopy.DestinationTableName = tableName sqlBulkCopy.BulkCopyTimeout = 3600 con.Open() sqlBulkCopy.WriteToServer(dt) con.Close() End Using End Using Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub) Await Task.WhenAll(Task1, Task2) End Function