使用我的代码成功保存交易后...我编辑交易然后保存...然后我想出了这个错误消息:
当分配给命令的连接处于挂起的本地事务中时,ExecuteNonQuery 要求该命令具有事务。该命令的 Transaction 属性尚未初始化。
这是我的代码:
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