after successfully saving a transaction using my code…I edit the transaction and then save…then i come up with this error message:
ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
here is my code:
Try
sqlTrans = sqlCon_.BeginTransaction(IsolationLevel.RepeatableRead)
sSQLAdapter_.UpdateBatchSize = 30
sCommand_ = DirectCast(sSQLAdapter_.SelectCommand, SqlCommand)
sCommand_.Connection = sqlCon_
sCommand_.Transaction = sqlTrans
sSQLAdapter.SelectCommand.Transaction = sqlTrans
sSQLAdapter_.Update(sDataSet.Tables(0))
sqlTrans.Commit()
sqlCon_.Close()
Catch ex As Exception
sqlTrans.Rollback()
Finally
sSQLAdapter.SelectCommand.Connection.Close()
sSQLAdapter.SelectCommand.Connection = Nothing
sSQLAdapter.SelectCommand.Transaction = Nothing
sSQLAdapter.SelectCommand.CommandText = ""
sSQLAdapter.SelectCommand.Dispose()
sqlTrans.Dispose()
sqlCon_.Close()
sqlCon_.Dispose()
End Try
You need to set Transaction object reference for
InsertCommand,UpdateCommandandDeleteCommandobject of SqlDataAdapter because you’re callingUpdatemethod.MSDN reference document – Using Transactions with a DataAdapter
Sample :