【问题标题】:Can't Update Values In Microsoft Access无法更新 Microsoft Access 中的值
【发布时间】:2017-11-08 15:06:58
【问题描述】:

我有一个问题,当我尝试更新数据时,程序没有将其保存在数据库中。

这是当前代码:

Dim y As Byte = Convert.ToByte(lblID.Text) - 1
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("dset").Rows(y).Item(1) = txtname.Text
ds.Tables("dset").Rows(y).Item(2) = txtsubm.Text & "/" & txtsubd.Text & "/" & txtsuby.Text
ds.Tables("dset").Rows(y).Item(3) = txtexpm.Text & "/" & txtexpd.Text & "/" & txtexpy.Text
ds.Tables("dset").Rows(y).Item(5) = txtnotes.Text
If MdComboBox1.SelectedItem = "A" Then
    ds.Tables("dset").Rows(y).Item(4) = "A"
ElseIf MdComboBox1.SelectedItem = "B" Then
Else
    MdAlertBox1.Text = "Please Select A Class The Class Box"
    MdAlertBox1.Visible = True
End If
MdAlertBox1.Text = "Data Sucessfully Updated !"
MdAlertBox1.kind = MDAlertBox._Kind.Success
MdAlertBox1.Visible = True
getinfo.Start()
updatedata.Stop()

以及声明的变量:

Dim conn As New OleDb.OleDbConnection
Dim DbProv As String = "PROVIDER=microsoft.ACE.OLEDB.12.0;"
Dim Src As String = " data source = c:\users\kingo\documents\visual studio 2013\Projects\WindowsApplication2\WindowsApplication2\BigGymDB.accdb"
Dim da As OleDb.OleDbDataAdapter
Dim ds As New DataSet

【问题讨论】:

  • 你一步步调试了吗?如果是,它会通过所有功能吗?
  • 是的,完全没有错误,是的,它成功了
  • 你在哪里打电话da.Update(ds.Tables("dset"))
  • 如何检查它们是否已更新?

标签: vb.net ms-access


【解决方案1】:

输入debug.print 以查看您传递给数据库的值。像这样:

    ds.Tables("dset").Rows(y).Item(2) = txtsubm.Text & "/" & txtsubd.Text & "/" & txtsuby.Text
    ds.Tables("dset").Rows(y).Item(3) = txtexpm.Text & "/" & txtexpd.Text & "/" & txtexpy.Text
    ds.Tables("dset").Rows(y).Item(5) = txtnotes.Text
    'your code ---^

    debug.print txtname.Text; txtsubm.Text & "/" & txtsubd.Text & "/" & txtsuby.Text; 
    debug.print txtnotes.Text; txtexpm.Text & "/" & txtexpd.Text & "/" & txtexpy.Text

    'your code ---v

    If MdComboBox1.SelectedItem = "A" Then
        ds.Tables("dset").Rows(y).Item(4) = "A"
    ElseIf MdComboBox1.SelectedItem = "B" Then

然后在即时窗口的两行中,您应该看到这些txtsub.Text 和其他3 个输入是否真的有东西。

【讨论】:

  • 确保它们有值,实际上值在更新后显示在表单的标签中,但是当我尝试再次调试时,旧值出现“它们没有分配给数据库”跨度>
  • @AdhamOmar - 无论如何,你的代码中有 On Error Resume Next 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多