【问题标题】:inserting new record in the msaccess using dataset使用数据集在 msaccess 中插入新记录
【发布时间】:2011-05-17 12:31:50
【问题描述】:

我正在尝试在 msaccess2003 mdb 文件中插入一条新记录,我的版本是 VB.net 2005,它没有显示任何错误,而且当我打开我的 access db 文件时,没有插入记录,以及我该如何格式化它给我的日期字段错误,我如何将 txtdate.text 转换为与 ms 访问兼容的日期

这里是代码

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim ds As New DataSet
    Dim db As New ClassDB

    ds = db.FetchData("ricemill.mdb", "sales")


    Dim anyRow As DataRow = ds.Tables(0).NewRow
    Dim mydate As DateTime
    Dim cmydate As String

    cmydate = txtdate.Text
    mydate = DateTime.Parse(mydate)


    anyRow("description") = txtdesc.Text
    anyRow("date") = DateTime.Parse(txtdate.Text)
    anyRow("amount") = txtamount.Text



    ds.Tables(0).Rows.Add(anyRow)
    ds.Tables(0).AcceptChanges()
    ds.AcceptChanges()

    MsgBox("Record Added ! ")

End Sub

【问题讨论】:

    标签: vb.net dataset add record


    【解决方案1】:

    好吧,我可以给你一个开始的提示(即使这是一个旧线程)如果我在一个月前开始我的项目时偶然发现这个很有用。

    您在这里所做的是虚拟创建了一个新行,并将其添加到您的虚拟数据库(数据集)

    acceptchanges 方法仅更改您的行与数据集的关系,它会提交更改,因此您的数据集不会将该行视为新创建的行,而是视为常规行。

    您想要打开一个连接,在 dataAdapter 上使用更新命令,因此它(DA)将查看数据集中的所有更改并将它们提交到实际数据库。

    我花了一段时间才让它工作,大部分是在测试和错误并阅读大量博客/互联网信息。

    http://msdn.microsoft.com/en-us/library/6264xxbd.aspx

    从这里开始,一旦您了解了 DA,您将非常接近您的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-28
      • 2010-11-18
      • 2019-08-19
      • 2012-07-01
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多