简体   繁体   English

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

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

I have set Oracle connection to DatagridView, via manager. 我已经通过管理器将Oracle连接设置为DatagridView。 Line for this is: 这行是:

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

Now I want to save all changes made in Datagridview to DB. 现在,我想将Datagridview中所做的所有更改保存到DB。 Tried this but not working: 尝试过此方法但不起作用:

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

What am I missing here ? 我在这里想念什么?

1.Maybe you are missing validate() and endEdit() ? 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. Do you have primary key for the table? 您有桌子的主键吗?

Update 更新资料

Fix the code I present - 修正我显示的代码-

Me.UsersBindingSource.EndEdit()

link 链接

Solved. 解决了。 Correct synthax is: 正确的合成胶为:

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 scion, thanks !! @the子孙,谢谢!

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

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