解决DataGridView最后修改单元格信息提交数据库更新丢失问题
重要说明:如果在提交数据库之前使用过DGV_PurviewList.CurrentCell = Nothing 方法
在提交数据库是二次使用有可能会让其失去效果,还是会出现保存不住的情况
Private Sub Update_RootList()
If init_VarFlag = True Then
Try
'*******关键语句***************
DGV_PurviewList.CurrentCell = Nothing '解决dgv结束编辑,提交最后更新单元格信息的问题
'*****************************
Dim SCB = New SqlCommandBuilder(da)
da.Update(dt)
MsgBox("更新成功")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If
End Sub
方法二:(Harry推荐使用)
更新前先使用下面两条语句,同步编辑内容,结束编辑状态
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
BindingContext(DataGridView1.DataSource).EndCurrentEdit()
DB_Update()
然后再调用更新模块
Private Sub DB_Update()
'...
End Sub

被折叠的 条评论
为什么被折叠?



