问题描述
大家好我正在测试 DBConcurrencyException 错误来有效地管理它,但我的测试项目似乎根本没有用。
我的表单有两个带有两个OdbcDataAdapter的datagridview和两个DataSet,每个DataSet绑定到每个datagridview但指向同一个表,就像两个使用相同应用程序数据的不同用户一样。
但是我试试为了保存第二个网格,我得到 DBConcurrencyException 并测试MSDN中的所有解决方案,但我无法正常工作。
我很乐意给你任何帮助。
我的代码
Public Class Form1
Private strCNN As String =" ;; DSN = TESTDB; UID = user; PWD = xx"
私有daTmp1为OdbcDataAdapter
私有cbCab1为新OdbcCommandBuilder()
私有dsCab1为新数据集
私有daTmp2为OdbcDataAdapter
私有cbCab2 As New OdbcCommandBuilder()
Private dsCab2 As New DataSet
Private strSql As String =" SELECT * FROM Pa_Cargos order by 1"
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
DataLoad()
End Sub
Private Sub DataLoad()
'Codigo para DataGrid 1 Code
daTmp1 = New OdbcDataAdapter(strSql,strCNN)
' ---
cbCab1.DataAdapter = daTmp1
'---
dsCab1.Clear()
daTmp1.Fill(dsCab1)
Me.DataGrid1 .DataSource = dsCab1.Tables(0)
Me.DataGrid1.Refresh()
'Codigo para DataGrid 2
daTmp2 = New OdbcDataAdapter(strSql,strCNN)
'---
cbCab2.DataAdapter = daTmp2
'---
dsCab2.Clear()
daTmp1.Fill(dsCab2)
Me.DataGrid2.DataSource = dsCab2.Tables(0)
Me.DataGrid2.Refresh()
End Sub
Private Sub cmdSaveGRid1_Click (ByVal发件人As System.Object,ByVal e As System.EventArgs)处理cmdSaveGRid1.Click
On Error GoTo Proc_Err
daTmp1.Update(dsCab1)
退出Sub
Proc_Err:
MsgBox(Err.Number& " - " &安培; Err.Description)
End Sub
'测试第二个网格 - 并发错误!!!
Private Sub cmdSaveGRid2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理cmdSaveGRid2.Click
On Error GoTo Proc_Err
Dim strUpdate As String = String.Empty
daTmp2.UpdateCommand = cbCab2.GetUpdateCommand
strUpdate =" UPDATE [Pa_Cargos] SET [COD_CARGO] =?,[DESCRIPCION] =?,[USR] = ?, [FEC_REG] =?,[STATUS] =? WHERE(([COD_CARGO] =?))"
daTmp2.UpdateCommand.CommandText = strUpdate
Debug.Print(daTmp2.UpdateCommand.CommandText)
daTmp2.Update(dsCab2)
退出Sub
Proc_Err:
daTmp2.UpdateCommand.CommandText = strUpdate
MsgBox(Err.Number&" - "& Err.Description)
'TestForErrors(dsCab2)
继续下一个
结束次级
结束等级
Hi all
I'am testing the DBConcurrencyException error to manage this efficiently, but my test project seem to be no working at all.
My form have tow datagridview with two OdbcDataAdapter, and two DataSet, each of one bind to each datagridview but pointing to the same table, like two differents users using the same applications data.
But I try to save the second grid I get the DBConcurrencyException and test all the solutions in MSDN but I can't get to work correctly.
I apreciate any help that you can give me.
My code
Public Class Form1 Private strCNN As String = ";DSN=TESTDB;UID=user;PWD=xx" Private daTmp1 As OdbcDataAdapter Private cbCab1 As New OdbcCommandBuilder() Private dsCab1 As New DataSet Private daTmp2 As OdbcDataAdapter Private cbCab2 As New OdbcCommandBuilder() Private dsCab2 As New DataSet Private strSql As String = " SELECT * FROM Pa_Cargos order by 1 " Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DataLoad() End Sub Private Sub DataLoad() 'Codigo para DataGrid 1 Code daTmp1 = New OdbcDataAdapter(strSql, strCNN) '--- cbCab1.DataAdapter = daTmp1 '--- dsCab1.Clear() daTmp1.Fill(dsCab1) Me.DataGrid1.DataSource = dsCab1.Tables(0) Me.DataGrid1.Refresh() 'Codigo para DataGrid 2 daTmp2 = New OdbcDataAdapter(strSql, strCNN) '--- cbCab2.DataAdapter = daTmp2 '--- dsCab2.Clear() daTmp1.Fill(dsCab2) Me.DataGrid2.DataSource = dsCab2.Tables(0) Me.DataGrid2.Refresh() End Sub Private Sub cmdSaveGRid1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveGRid1.Click On Error GoTo Proc_Err daTmp1.Update(dsCab1) Exit Sub Proc_Err: MsgBox(Err.Number & " - " & Err.Description) End Sub 'Test the Second Grid - Concurrency Error !!! Private Sub cmdSaveGRid2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveGRid2.Click On Error GoTo Proc_Err Dim strUpdate As String = String.Empty daTmp2.UpdateCommand = cbCab2.GetUpdateCommand strUpdate = "UPDATE [Pa_Cargos] SET [COD_CARGO] = ?, [DESCRIPCION] = ?, [USR] = ?, [FEC_REG] = ?, [STATUS] = ? WHERE (([COD_CARGO] = ?)) " daTmp2.UpdateCommand.CommandText = strUpdate Debug.Print(daTmp2.UpdateCommand.CommandText) daTmp2.Update(dsCab2) Exit Sub Proc_Err: daTmp2.UpdateCommand.CommandText = strUpdate MsgBox(Err.Number & " - " & Err.Description) 'TestForErrors(dsCab2) Resume Next End Sub End Class
这篇关于DataAdapter.Update(Dataset)'并发冲突:UpdateCommand影响了预期的1条记录中的0条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!