并发冲突:UpdateCommand影响了预期的1条记录中的0条. [英] Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

查看:111
本文介绍了并发冲突:UpdateCommand影响了预期的1条记录中的0条.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个应用程序,该应用程序可以滴答和取消滴答路由序列.但是,当我在要求中勾选要求后单击保存按钮时,就会出现一个异常,提示"并发冲突:UpdateCommand影响了预期的1条记录中的0条".我的代码如下:

I have created an application which ticks and unticks a routing sequence. But whenever I click on my save button after tickin the required, I get an exception thrown at me stating "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records". My code is as follows:

私人 Sub OKButton_Click( ByVal 发送者 As 系统.对象 ByVal e As System.EventArgs) 句柄 OKButton.单击

Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKButton.Click

'在dataGridView中显示行.
Me .myadapter.SelectCommand.CommandText = " SELECT dbo.WR010130.RTSEQNUM_I," _
&
" RTSEQDES_I,SCHEDULESTARTDATE_I,DONECB_I," _
&
" CLOSEDBY_I,DATECLOSED_I,TIMECLOSED_I,SCHEDULESTARTDATE_I,WCID_I _
&
" FROM dbo.WR010130在dbo.WR010130.MANUFACTUREORDER_I = dbo.WO010032.MANUFACTUREORDER_I上加入WO010032, _
&
" WHERE dbo.WR010130.MANUFACTUREORDER_I ='" & MoNoComboBox.Text& "' AND(dbo.WO010032.MANUFACTUREORDERST_I = 3 OR dbo.WO010032.MANUFACTUREORDERST_I = 7)"

'Displaying the rows in the dataGridView.
Me.myadapter.SelectCommand.CommandText = "SELECT dbo.WR010130.RTSEQNUM_I, " _
&
"RTSEQDES_I, SCHEDULESTARTDATE_I, DONECB_I, " _
&
"CLOSEDBY_I, DATECLOSED_I, TIMECLOSED_I, SCHEDULESTARTDATE_I, WCID_I " _
&
"FROM dbo.WR010130 JOIN WO010032 ON dbo.WR010130.MANUFACTUREORDER_I = dbo.WO010032.MANUFACTUREORDER_I " _
&
"WHERE dbo.WR010130.MANUFACTUREORDER_I = '" & MoNoComboBox.Text & "' AND (dbo.WO010032.MANUFACTUREORDERST_I = 3 OR dbo.WO010032.MANUFACTUREORDERST_I = 7)"

.myadapter.Fill( .RSdataset.Tables( " WR010130; ))
WR010130DataGridView.Show()
WR010130DataGridView.DataSource =
Me .RSdataset.Tables( " WR010130" )

Me.myadapter.Fill(Me.RSdataset.Tables("WR010130"))
WR010130DataGridView.Show()
WR010130DataGridView.DataSource =
Me.RSdataset.Tables("WR010130")

结束

私人 Sub SaveButton_Click( ByVal 发件人 System.Object, ByVal e As System.EventArgs) 句柄 SaveButton.单击

Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click

'更改日期格式为mm/dd/yyyy.
暗淡 date1 日期
date1 = 日期 .Today
暗淡 string1 字符串
string1 = date1. "/" & date1.Day& "/" & date1.Year

'Changing any format of date in the mm/dd/yyyy format.
Dim date1 As Date
date1 = Date.Today
Dim string1 As String
string1 = date1.Month & "/" & date1.Day & "/" & date1.Year

尝试
'通过检查每一行以更新dataGridView中显示的数据值=1.
暗淡 dr 新建 DataGridViewRow
对于 每个 dr Me .WR010130DataGridView.Rows
If dr.Cells( " DoneDataGridViewCheckBoxColumn" ).Value = 1 然后

Try
'Updating the data displayed in the dataGridView by checking each and every row for value = 1.
Dim dr As New DataGridViewRow
For Each dr In Me.WR010130DataGridView.Rows
If dr.Cells("DoneDataGridViewCheckBoxColumn").Value = 1 Then

myadapter.UpdateCommand = 新建 SqlCommand( " UPDATE WR010130" _
&
""SET DONECB_I = 1,CLOSEDBY_I ='" & MainForm.UserToolStripStatusLabel.Text& ,'," /font> _
&
" DATECLOSED_I ='" & LoginForm.strdt& "'," _
&
" TIMECLOSED_I ='" & TimeOfDay& "' ," _
&
&; ACTUALFINISHDATE_I ='" & string1& "',ACTUALFINISHTI ME_I ='" &每日时间& "', _
&
" ACTUALSTARTDATE_I ='" &字符串1& "',ACTUALSTARTTIME_I ='" &每日时间& "' " _
&
" WHERE(MANUFACTUREORDER_I ='" & MoNoComboBox.Text& "')和" _
&
''(RTSEQNUM_I =''" & dr.Cells(1).Value& "')" )

myadapter.UpdateCommand = New SqlCommand("UPDATE WR010130 " _
&
"SET DONECB_I = 1, CLOSEDBY_I = '" & MainForm.UserToolStripStatusLabel.Text & "', " _
&
"DATECLOSED_I = '" & LoginForm.strdt & "', " _
&
"TIMECLOSED_I = '" & TimeOfDay & "', " _
&
"ACTUALFINISHDATE_I = '" & string1 & "', ACTUALFINISHTIME_I = '" & TimeOfDay & "', " _
&
"ACTUALSTARTDATE_I = '" & string1 & "', ACTUALSTARTTIME_I = '" & TimeOfDay & "' " _
&
"WHERE (MANUFACTUREORDER_I = '" & MoNoComboBox.Text & "') AND " _
&
"(RTSEQNUM_I = '" & dr.Cells(1).Value & "')")

暗淡 modifiedTable2 As DataTable = RSdataset.Tables(0).GetChanges(DataRowState.Modified)
myadapter.Update(modifiedTable2) 结束 如果
下一个

Dim modifiedTable2 As DataTable = RSdataset.Tables(0).GetChanges(DataRowState.Modified)
myadapter.Update(modifiedTable2) ---> I get the concurrency voilation error here
End If
Next

.myadapter.Update( .RSdataset.Tables( " WR010130" ))

Me.myadapter.Update(Me.RSdataset.Tables("WR010130"))

捕获 ex As 例外

Catch ex As Exception

MsgBox(ex.Message)

MsgBox(ex.Message)

结束 尝试

End Try

结束

请有人帮我,这个异常使我发疯

Please somebody help me this exception is driving me crazy

请提出我在做错什么或应该怎么做才能使它正常工作.

推荐答案

当我有另一个线程同时更新同一表或数据集时,我似乎得到了此异常.

I seem to get this exception when i have another thread updating the same table or dataset at the same time.

调用此函数时,是否还有其他数据库事务在发生?

Are there any other database transactions occuring when you are calling this function.

还要考虑您的where子句可能返回零行.

Also consider that your where clause may be returning zero rows.

欢呼

马特


这篇关于并发冲突:UpdateCommand影响了预期的1条记录中的0条.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆