我编的数据库程序在窗体上有增加和删除按钮,增加可以更新数据库,但为什么删除时不能更新?(没有出错信息,在datagrid1上当按删除钮时可看到数据跟着删除),代码如下: Public Class frmjbdw Inherits System.Windows.Forms.Form
Sub updatadw() cmdbuilder = New OleDbCommandBuilder(adpter) adpter.Update(ds.Tables("jbdw")) con.Close() DataGrid1.ReadOnly = True End Sub
Private Sub frmjbdw_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load opendb() If con.State = ConnectionState.Closed Then con.Open() adpter = New OleDbDataAdapter("select * from jbdw", con) ds = New DataSet adpter.Fill(ds, "jbdw") DataGrid1.ReadOnly = True DataGrid1.DataSource = ds.Tables("jbdw") con.Close()
End Sub
Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
updatadw()
End Sub
Private Sub Cancl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click con.Close() Me.Dispose() End Sub
Private Sub Delect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim rowno = DataGrid1.CurrentRowIndex ds.Tables("jbdw").Rows.Remove(ds.Tables("jbdw").Rows(rowno)) ds.Tables("jbdw").AcceptChanges()
updatadw()
End Sub End Class