DOBON.NET DOBON.NETプログラミング掲示板過去ログ

親子関係を持つテーブルの同時実行違反

環境/言語:[WinXP・VB.net ent・ACCESS2000]
分類:[.NET]

 すいませんよろしくお願いします。
 データベース作成では避けることのできない同時実行違反ですが、
 不可解な現象が起きてしまい困っています。
 親テーブルはテキストボックスに、子テーブルはデータグリッドに表示していま す。
 処理の流れは、
 @子テーブルでのUPDATE
 A子テーブルで同時実行違反の発生
 BDataReaderを使ってエラー行の内容を取得
 CDetaSet内のエラー行にDataReader内エラー行の内容を代入
 DAcceptChanges()をエラー行につかって行バージョンをUncangedに変更
 と全て正常に機能している様なのになぜか、データグリッド内にUncangedにした 行が追加されてしまいます。(エラー行はそのまま存在)
 一応そのまま使用しても、代入後の行はデータベースへの変更も受け付けます。
 でもそのままでは(エラー行はそのまま存在している状態)毎回同時実行違反と
 なります。またデータベース側では行は増えていません(結局エラー行はないも 同然)。とかなり不可解です。今回代入行をわざわざMds1.order.Rows(r)と指定 しているのはdbcx.Rowに代入しても何も起きないからです(当たり前?)。
また子テーブルにも主キーが設定されています。
 以下できるだけ原文のままソースをさらしますのでわかる方レスお願いします。
Try
subAdapter.Update(ds1.GetChanges())
MessageBox.Show("更新は成功しました。")
ds1.AcceptChanges()
Catch dbcx As DBConcurrencyException
Dim reloadCmd1 As New System.Data.OleDb.OleDbCommand( _
"SELECT 〜 FROM 〜 WHERE NO = @NO", OleDbConnection1)
reloadCmd1.Parameters.Add(New System.Data.OleDb.OleDbParameter ("@NO", System.Data.OleDb.OleDbType.Integer, 0, "@NO")).Value = dbcx.Row("NO")
OleDbConnection1.Open()
Dim reader1 As System.Data.OleDb.OleDbDataReader = reloadCmd1.ExecuteReader()
Dim r As Integer
Dim response As System.Windows.Forms.DialogResult
If reader1.Read Then
response = MessageBox.Show("競合が発生しました。最新の情報を取得しますか?", "", MessageBoxButtons.YesNo)
Select Case response
Case System.Windows.Forms.DialogResult.Yes
Me.BindingContext(dbcx.Row).Position = r
ds1.order.Rows(r)("a") = reader1.GetValue(0)
ds1.order.Rows(r)("b") = reader1.GetValue(1)
ds1.order.Rows(r)("c") = reader1.GetValue(2)
ds1.order.Rows(r)("d") = reader1.GetValue(3)
ds1.order.Rows(r)("e") = reader1.GetValue(4)
ds1.order.Rows(r)("f") = reader1.GetValue(5)
ds1.order.Rows(r)("g") = reader1.GetValue(6)
ds1.order.Rows(r)("h") = reader1.GetValue(7)
ds1.order.Rows(r)("i") = reader1.GetValue(8)
ds1.order.Rows(r)("j") = reader1.GetValue(9)
ds1.order.Rows(r)("k") = reader1.GetValue(10)
ds1.order.Rows(r)("l") = reader1.GetValue(11)
ds1.order.Rows(r)("m") = reader1.GetValue(12)
ds1.order.Rows(r)("n") = reader1.GetValue(13)
ds1.order.Rows(r)("o") = reader1.GetValue(14)
ds1.order.Rows(r)("p") = reader1.GetValue(15)
ds1.order.Rows(r).RowError = Nothing
ds1.order.Rows(r).AcceptChanges()
Case System.Windows.Forms.DialogResult.No
reader1.Close()
Exit Sub
End Select
Else
ds1.Tables("order").Rows.Remove(dbcx.Row)
Debug.Write("該当情報は有効ではありません。")
End If
MessageBox.Show("編集をやり直してください")
reader1.Close()
OleDbConnection1.Close()
Catch cx As Exception
MessageBox.Show(cx.Message, cx.GetType().ToString())
End Try
End Sub

自己レスです解決しました。結局以下のような間抜けなコードを書いていただけのようです。
Dim r As Integer
> Me.BindingContext(dbcx.Row).Position = r
> ds1.order.Rows(r)("e") = reader1.GetValue(4)

 変数rにはどんな数が入ったのか定かではありませんが、初歩的な間違いをしてしまったものです。
解決策は
     Dim r As Integer
> r = reader1.GetValue(0)
> ds1.order.Rows(r)("e") = reader1.GetValue(4)
としてdatareaderの値をキーとしました。ではまたよろしくお願いします。
解決済み!

DOBON.NET | プログラミング道 | プログラミング掲示板