lmummy
lmummy
采纳率0%
2016-08-25 05:48 阅读 2.0k

vb.net bindingsource 绑定ACCESS数据源不能更新数据问题

60

求各位大神给看一下~~
vb.net 绑定ACCESS数据库用到的控件是bindingnavigator、bindingsource、datagridview
bindingnavigator用于点击删除增加保存按钮
bindingsource用于绑定数据源
datagridview用于显示数据表

程序代码如下:
Imports System.Data.OleDb

Public Class Frm

    Private Adapter As New OleDbDataAdapter
Private Table As New DataTable

Private Sub Frm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    Table.Clear()

    Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="  &DBPath)
    Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(Adapter)
    Dim cmd As OleDbCommand = New OleDbCommand("Select * From 表", conn)

    Adapter.SelectCommand = cmd
    Adapter.Fill(Table)

    datagridview.AutoGenerateColumns = False
    bindingsource.DataSource = Table
    datagridview.DataSource = bindingsource
    bindingnavigator.BindingSource =bindingsource

End Sub

以上可以成功绑定并显示数据表

bindingnavigator控件进行了绑定,所以可以直接点击上面的删除增加等按钮,删除某一行数据后点击下面保存是没问题的,数据库里面也确实删除了,但是进行修改或者增存一行数据后点击下面保存,数据库没有能更新数据,为什么能删除确不能修改和增加,不太清楚怎么回事了,哪位大神给解答一下,谢谢~~
Private Sub SaveChange_Click(sender As System.Object, e As System.EventArgs) Handles SaveChange.Click

    Adapter.Update(Table)

    datagridview.Refresh()

End Sub

End Class

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • devmiao devmiao 2016-08-25 10:05

    检查下你的代码,自己多动手动脑才能进步的。

    点赞 评论 复制链接分享

相关推荐