繁体   English   中英

VB.NET-将Datagridview中的更改保存到数据库

[英]VB.NET - Save changes in Datagridview to DB

我已经通过管理器将Oracle连接设置为DatagridView。 这行是:

  Me.UsersTableAdapter.Fill(Me.MyDataSet._Users)

现在,我想将Datagridview中所做的所有更改保存到DB。 尝试过此方法但不起作用:

 Me.UsersTableAdapter.Update(Me.MyDataSet._Users)

我在这里想念什么?

1.也许您缺少validate()endEdit()吗?

Try
    Me.Validate()
    Me.UsersBindingSource.EndEdit()
    Me.UsersTableAdapter.Update(Me.MyDataSet._Users)
    MsgBox("Update successful")

Catch ex As Exception
    MsgBox("Update failed")
End Try
  1. 您有桌子的主键吗?

更新资料

修正我显示的代码-

Me.UsersBindingSource.EndEdit()

链接

解决了。 正确的合成胶为:

Try
    Me.Validate()
    Me.UsersBindingSource.EndEdit()
    Me.UsersTableAdapter.Update(Me.MyDataSet._Users)
    MsgBox("Update successful")

Catch ex As Exception
    MsgBox("Update failed")
End Try

@the子孙,谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM