VB Net CommandBuilder with Transaction (ODBC)
Dim cbWarehouse As New SqlCommandBuilder(daWarehouse)
Dim warehouseDelete As SqlCommand = cbWarehouse.GetDeleteCommand()
Dim warehouseInsert As SqlCommand = cbWarehouse.GetInsertCommand()
Dim warehouseUpdate As SqlCommand = cbWarehouse.GetUpdateCommand()
Dim cbSite As New SqlCommandBuilder(daSite)
Dim siteDelete As SqlCommand = cbSite.GetDeleteCommand()
Dim siteInsert As SqlCommand = cbSite.GetInsertCommand()
Dim siteUpdate As SqlCommand = cbSite.GetUpdateCommand()
' Fill the DataSet.
daWarehouse.Fill(ds, "WarehouseInventory")
daSite.Fill(ds, "SiteInventory")
' Begin the transaction and enlist the commands.
Dim tran As SqlTransaction = conn.BeginTransaction()
warehouseDelete.Transaction = tran
warehouseInsert.Transaction = tran
warehouseUpdate.Transaction = tran
siteDelete.Transaction = tran
siteInsert.Transaction = tran
siteUpdate.Transaction = tran
'Commit the transaction
tran.Commit()
Catch ex As SqlException
'Roll back the transaction.
'Additional error handling if needed.
tran.Rollback()
Finally
' Close the connection.
conn.Close()
End Try
沒有留言:
張貼留言